# HG changeset patch # User Pierre-Yves David # Date 1676908630 -3600 # Node ID 8ba5028de859340d990539eb60c49d6d6753c933 # Parent 72ef6c4888da80c302ecf4dc9a33caed564fee30 dirstate: check that dirstate is clean at the initial context opening More checking that we are not doing anything weird. diff -r 72ef6c4888da -r 8ba5028de859 mercurial/dirstate.py --- a/mercurial/dirstate.py Tue Feb 21 22:32:04 2023 +0100 +++ b/mercurial/dirstate.py Mon Feb 20 16:57:10 2023 +0100 @@ -235,6 +235,19 @@ E1: elif lock was acquired → write the changes E2: else → discard the changes """ + is_changing = self.is_changing_any + has_tr = repo.currenttransaction is not None + nested = bool(self._running_status) + + first_and_alone = not (is_changing or has_tr or nested) + + # enforce no change happened outside of a proper context. + if first_and_alone and self._dirty: + has_tr = repo.currenttransaction() is not None + if not has_tr and self._changing_level == 0 and self._dirty: + msg = "entering a status context, but dirstate is already dirty" + raise error.ProgrammingError(msg) + self._running_status += 1 try: yield