[Bug 6233] New: `hg commit --amend` can corrupt dirstate if files are modified while editor is open

mercurial-bugs at mercurial-scm.org mercurial-bugs at mercurial-scm.org
Tue Nov 26 01:01:55 UTC 2019


https://bz.mercurial-scm.org/show_bug.cgi?id=6233

            Bug ID: 6233
           Summary: `hg commit --amend` can corrupt dirstate if files are
                    modified while editor is open
           Product: Mercurial
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: feature
          Priority: wish
         Component: Mercurial
          Assignee: bugzilla at mercurial-scm.org
          Reporter: hg at pewpew.net
                CC: mercurial-devel at mercurial-scm.org
    Python Version: 2.7

Basically: run `hg commit --amend`, and while the editor is open, modify one of
the files again. Save and quit the editor. There is a high likelihood (if the
file isn't new, I've reproduced this 100% of the time) that the modifications
made coincident with the editor invocation are NOT picked up, but that the
dirstate IS updated to say that they have been.


Example .t test, at 5.1.2+537-6a350194de7f, this produces:
-  OK.
+  Bug detected. 'delta' is not part of the commit OR the wdir
+  Diff and status before rebuild:
+  Diff and status after rebuild:
+  diff --git a/foo b/foo
+  --- a/foo
+  +++ b/foo
+  @@ -1,2 +1,3 @@
+   alpha
+   beta
+  +delta
+  M foo


Modifying a file while the editor is open can cause dirstate corruption

  $ hg init modify-during-amend; cd modify-during-amend
  $ echo r0 > foo; hg commit -qAm "r0"
  $ echo alpha > foo; hg commit -qm "alpha"
  $ echo beta >> foo
  $ cat > $TESTTMP/sleepy_editor <<EOF
  > sleep 3
  > EOF
  $ chmod +x $TESTTMP/sleepy_editor
  $ HGEDITOR=$TESTTMP/sleepy_editor hg commit --amend &
  $ sleep 1
  $ echo delta >> foo
  $ sleep 3
  $ if (hg diff -c . | grep -q 'delta') || [[ -n "$(hg status)" ]]; then
  >   echo "OK."
  > else
  >   echo "Bug detected. 'delta' is not part of the commit OR the wdir"
  >   echo "Diff and status before rebuild:"
  >   hg diff
  >   hg status
  >   hg debugrebuilddirstate
  >   echo "Diff and status after rebuild:"
  >   hg diff
  >   hg status
  > fi
  OK.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Mercurial-devel mailing list