D4419: rename: return error status if any rename/copy failed

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Wed Aug 29 17:48:33 UTC 2018


martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Ever since https://phab.mercurial-scm.org/rHG447ea621e50e3eff380e863cf7f8ff71b2b9318e (copy: propagate errors properly, 2007-12-06),
  we have returned an error status if the source file did not
  exist. That commit did not return error status for any other errors,
  and it's unclear if that was on purpose or not. It seems to me like we
  should return an error in the other cases to, so that's what this
  patch does.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D4419

AFFECTED FILES
  mercurial/cmdutil.py
  tests/test-copy.t
  tests/test-rename.t

CHANGE DETAILS

diff --git a/tests/test-rename.t b/tests/test-rename.t
--- a/tests/test-rename.t
+++ b/tests/test-rename.t
@@ -71,6 +71,7 @@
 
   $ hg rename --after d1/a dummy
   d1/a: not recording move - dummy does not exist
+  [1]
 
 move a single file to an existing directory
 
@@ -268,6 +269,7 @@
   d2/b: not overwriting - file already committed
   ('hg rename --force' to replace the file by recording a rename)
   moving d1/d11/a1 to d2/d11/a1
+  [1]
   $ hg status -C
   A d2/a
     d1/a
@@ -338,6 +340,7 @@
   d1/b: not recording move - d2/d21/b does not exist
   d1/ba: not recording move - d2/d21/ba does not exist
   moving d1/d11/a1 to d2/d21/a1
+  [1]
   $ hg status -C
   A d2/d21/a
     d1/a
@@ -372,6 +375,7 @@
   $ hg rename d1/ba d1/ca
   d1/ca: not overwriting - file exists
   ('hg rename --after' to record the rename)
+  [1]
   $ hg status -C
   ? d1/ca
   $ hg update -C
@@ -396,6 +400,7 @@
   $ hg rename --traceback d1/ba d1/ca
   d1/ca: not overwriting - file exists
   ('hg rename --after' to record the rename)
+  [1]
   $ hg status -C
   ? d1/ca
   $ hg update -C
@@ -421,6 +426,7 @@
   $ hg rename d1/* d2/* d3
   moving d1/d11/a1 to d3/d11/a1
   d3/b: not overwriting - d2/b collides with d1/b
+  [1]
   $ hg status -C
   A d3/a
     d1/a
diff --git a/tests/test-copy.t b/tests/test-copy.t
--- a/tests/test-copy.t
+++ b/tests/test-copy.t
@@ -148,6 +148,7 @@
 copy --after to a nonexistent target filename
   $ hg cp -A foo dummy
   foo: not recording copy - dummy does not exist
+  [1]
 
 dry-run; should show that foo is clean
   $ hg copy --dry-run foo bar
@@ -225,11 +226,13 @@
   $ hg copy -A bar foo
   foo: not overwriting - file already committed
   ('hg copy --after --force' to replace the file by recording a copy)
+  [1]
 same error without the --after, so the user doesn't have to go through
 two hints:
   $ hg copy bar foo
   foo: not overwriting - file already committed
   ('hg copy --force' to replace the file by recording a copy)
+  [1]
 but it's considered modified after a copy --after --force
   $ hg copy -Af bar foo
   $ hg st -AC foo
@@ -241,5 +244,6 @@
   $ hg cp bar xyzzy
   xyzzy: not overwriting - file exists
   ('hg copy --after' to record the copy)
+  [1]
 
   $ cd ..
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1184,7 +1184,7 @@
             ui.warn(_('%s: not overwriting - %s collides with %s\n') %
                     (reltarget, repo.pathto(abssrc, cwd),
                      repo.pathto(prevsrc, cwd)))
-            return
+            return True # report a failure
 
         # check for overwrites
         exists = os.path.lexists(target)
@@ -1194,7 +1194,7 @@
                 repo.dirstate.normalize(abstarget)):
                 if not rename:
                     ui.warn(_("%s: can't copy - same file\n") % reltarget)
-                    return
+                    return True # report a failure
                 exists = False
                 samefile = True
 
@@ -1220,7 +1220,7 @@
                         hint = _("('hg copy --after' to record the copy)\n")
                 ui.warn(msg % reltarget)
                 ui.warn(hint)
-                return
+                return True # report a failure
 
         if after:
             if not exists:
@@ -1230,7 +1230,7 @@
                 else:
                     ui.warn(_('%s: not recording copy - %s does not exist\n') %
                             (relsrc, reltarget))
-                return
+                return True # report a failure
         elif not dryrun:
             try:
                 if exists:



To: martinvonz, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list