tests: demonstrate bug in `hg fix` with incorrectly dirty working copy stable
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 22 Jul 2021 17:12:56 -0700
branchstable
changeset 47765 184d83ef2e59
parent 47764 6b9ad3a0c348
child 47766 3feda1e779d4
tests: demonstrate bug in `hg fix` with incorrectly dirty working copy If the parent commit needs formatting but the working copy already has the correct formatting, then the working copy will be reported as modified even though it's clean (because the size in the dirstate is incorrect). Because the bug only occurs when the size changes, I modified the formatter used in the test case to remove repeated spaces. Differential Revision: https://phab.mercurial-scm.org/D11208
tests/test-fix.t
--- a/tests/test-fix.t	Wed Jul 21 15:50:17 2021 -0400
+++ b/tests/test-fix.t	Thu Jul 22 17:12:56 2021 -0700
@@ -3,6 +3,7 @@
 
   $ UPPERCASEPY="$TESTTMP/uppercase.py"
   $ cat > $UPPERCASEPY <<EOF
+  > import re
   > import sys
   > from mercurial.utils.procutil import setbinary
   > setbinary(sys.stdin)
@@ -10,16 +11,18 @@
   > stdin = getattr(sys.stdin, 'buffer', sys.stdin)
   > stdout = getattr(sys.stdout, 'buffer', sys.stdout)
   > lines = set()
+  > def format(text):
+  >   return re.sub(b' +', b' ', text.upper())
   > for arg in sys.argv[1:]:
   >   if arg == 'all':
-  >     stdout.write(stdin.read().upper())
+  >     stdout.write(format(stdin.read()))
   >     sys.exit(0)
   >   else:
   >     first, last = arg.split('-')
   >     lines.update(range(int(first), int(last) + 1))
   > for i, line in enumerate(stdin.readlines()):
   >   if i + 1 in lines:
-  >     stdout.write(line.upper())
+  >     stdout.write(format(line))
   >   else:
   >     stdout.write(line)
   > EOF
@@ -354,6 +357,24 @@
 
   $ cd ..
 
+Test that the working copy is reported clean if formatting of the parent makes
+it clean.
+  $ hg init wc-already-formatted
+  $ cd wc-already-formatted
+
+  $ printf "hello   world\n" > hello.whole
+  $ hg commit -Am initial
+  adding hello.whole
+  $ hg fix -w *
+  $ hg st
+  M hello.whole
+  $ hg fix -s . *
+  $ hg st
+  M hello.whole (known-bad-output !)
+  $ hg diff
+
+  $ cd ..
+
 Test the effect of fixing the working directory for each possible status, with
 and without providing explicit file arguments.