Patchwork [2,of,3,STABLE,V2] rename: properly report removed and added file as modified (issue4458)

login
register
mail settings
Submitter Pierre-Yves David
Date Nov. 27, 2014, 1:16 a.m.
Message ID <6c8af433ac6e7ec4870d.1417051014@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/6879/
State Accepted
Commit 2963d5c9d90ba0060ee7d552c3b56b95aca5fcd3
Headers show

Comments

Pierre-Yves David - Nov. 27, 2014, 1:16 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1416883376 28800
#      Mon Nov 24 18:42:56 2014 -0800
# Branch stable
# Node ID 6c8af433ac6e7ec4870d05db82a6671620329240
# Parent  b22e0b171d5c84fec5129a142806c708090d5c8e
rename: properly report removed and added file as modified (issue4458)

The result of 'hg rm' + 'hg rename' disagreed with the one from
'hg rename --force'. We align them on 'hg move --force' because it agree with
what 'hg status' says after the commit.

Stopping to repor modified file as added put an end to hg revert confusion in this
situation (issue4458).

However, reporting file as modified also prevent revert to restore the copy
source. We fix this in a later changesets.

Git diff also stop reporting the add in the middle of the chain as add. Not
sure how important (and even wrong) it is.

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1335,12 +1335,14 @@  class workingctx(committablectx):
             self._repo.ui.warn(_("copy failed: %s is not a file or a "
                                  "symbolic link\n") % dest)
         else:
             wlock = self._repo.wlock()
             try:
-                if self._repo.dirstate[dest] in '?r':
+                if self._repo.dirstate[dest] in '?':
                     self._repo.dirstate.add(dest)
+                elif self._repo.dirstate[dest] in 'r':
+                    self._repo.dirstate.normallookup(dest)
                 self._repo.dirstate.copy(source, dest)
             finally:
                 wlock.release()
 
     def _filtersuspectsymlink(self, files):
diff --git a/tests/test-mq-qrename.t b/tests/test-mq-qrename.t
--- a/tests/test-mq-qrename.t
+++ b/tests/test-mq-qrename.t
@@ -74,12 +74,12 @@  Test overlapping renames (issue2388)
   $ hg qnew patchb
   $ hg ci --mq -m c1
   $ hg qrename patchb patchc
   $ hg qrename patcha patchb
   $ hg st --mq
+  M patchb
   M series
-  A patchb
   A patchc
   R patcha
   $ cd ..
 
 Test renames with mq repo (issue2097)
diff --git a/tests/test-rename.t b/tests/test-rename.t
--- a/tests/test-rename.t
+++ b/tests/test-rename.t
@@ -569,19 +569,28 @@  transitive rename --after
 overwriting with renames (issue1959)
 
   $ hg rename d1/a d1/c
   $ hg rename d1/b d1/a
   $ hg status -C
-  A d1/a
+  M d1/a
     d1/b
   A d1/c
     d1/a
   R d1/b
   $ hg diff --git
-  diff --git a/d1/b b/d1/a
-  rename from d1/b
-  rename to d1/a
+  diff --git a/d1/a b/d1/a
+  --- a/d1/a
+  +++ b/d1/a
+  @@ -1,1 +1,1 @@
+  -d1/a
+  +d1/b
+  diff --git a/d1/b b/d1/b
+  deleted file mode 100644
+  --- a/d1/b
+  +++ /dev/null
+  @@ -1,1 +0,0 @@
+  -d1/b
   diff --git a/d1/a b/d1/c
   copy from d1/a
   copy to d1/c
   $ hg update -C
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
diff --git a/tests/test-status.t b/tests/test-status.t
--- a/tests/test-status.t
+++ b/tests/test-status.t
@@ -388,5 +388,51 @@  warning message about such pattern.
   $ hg --config ui.slash=false status -A --rev 1 1
   R 1\2\3\4\5\b.txt
 #endif
 
   $ cd ..
+
+Status after move overwriting a file (issue4458)
+=================================================
+
+
+  $ hg init issue4458
+  $ cd issue4458
+  $ echo a > a
+  $ echo b > b
+  $ hg commit -Am base
+  adding a
+  adding b
+
+
+with --force
+
+  $ hg mv b --force a
+  $ hg st --copies
+  M a
+    b
+  R b
+  $ hg revert --all
+  reverting a
+  undeleting b
+  $ rm *.orig
+
+without force
+
+  $ hg rm a
+  $ hg st --copies
+  R a
+  $ hg mv b a
+  $ hg st --copies
+  M a
+    b
+  R b
+
+Other "bug" highlight, the revision status does not report the copy information.
+This is buggy behavior.
+
+  $ hg commit -m 'blah'
+  $ hg st --copies --change .
+  M a
+  R b
+
+  $ cd ..