rename: make --after work if source is already in R state
authorPeter Arrenbrecht <peter.arrenbrecht@gmail.com>
Wed, 26 May 2010 16:16:47 +0200
changeset 11223 0d09f2244805
parent 11222 e7adcef1504b
child 11224 f23f87462c18
rename: make --after work if source is already in R state I routinely want to use `hg addrem` and then fix up missed renames manually using `hg mv -A`. This patch allows me to record such renames from a source in state R to a target in state A.
mercurial/cmdutil.py
tests/test-rename
tests/test-rename.out
--- a/mercurial/cmdutil.py	Tue May 25 18:45:44 2010 +0200
+++ b/mercurial/cmdutil.py	Wed May 26 16:16:47 2010 +0200
@@ -351,12 +351,13 @@
 
     def walkpat(pat):
         srcs = []
+        badstates = after and '?' or '?r'
         m = match(repo, [pat], opts, globbed=True)
         for abs in repo.walk(m):
             state = repo.dirstate[abs]
             rel = m.rel(abs)
             exact = m.exact(abs)
-            if state in '?r':
+            if state in badstates:
                 if exact and state == '?':
                     ui.warn(_('%s: not copying - file is not managed\n') % rel)
                 if exact and state == 'r':
--- a/tests/test-rename	Tue May 25 18:45:44 2010 +0200
+++ b/tests/test-rename	Wed May 26 16:16:47 2010 +0200
@@ -23,6 +23,14 @@
 hg update -C
 rm d2/c
 
+echo '# rename --after a single file when src and tgt already tracked'
+mv d1/d11/a1 d2/c
+hg addrem
+hg rename --after d1/d11/a1 d2/c
+hg status -C
+hg update -C
+rm d2/c
+
 echo "# rename --after a single file to a nonexistant target filename"
 hg rename --after d1/a dummy
 
--- a/tests/test-rename.out	Tue May 25 18:45:44 2010 +0200
+++ b/tests/test-rename.out	Wed May 26 16:16:47 2010 +0200
@@ -8,6 +8,13 @@
   d1/d11/a1
 R d1/d11/a1
 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+# rename --after a single file when src and tgt already tracked
+removing d1/d11/a1
+adding d2/c
+A d2/c
+  d1/d11/a1
+R d1/d11/a1
+1 files updated, 0 files merged, 0 files removed, 0 files unresolved
 # rename --after a single file to a nonexistant target filename
 d1/a: not recording move - dummy does not exist
 # move a single file to an existing directory