changeset 39350:5b92a717bfc1

rename: return error status if any rename/copy failed Ever since 447ea621e50e (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. Differential Revision: https://phab.mercurial-scm.org/D4419
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 29 Aug 2018 09:59:08 -0700
parents 534e451b6dda
children 4cfd1eebe6aa
files mercurial/cmdutil.py tests/test-copy.t tests/test-rename.t
diffstat 3 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Wed Aug 29 09:54:50 2018 -0700
+++ b/mercurial/cmdutil.py	Wed Aug 29 09:59:08 2018 -0700
@@ -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:
--- a/tests/test-copy.t	Wed Aug 29 09:54:50 2018 -0700
+++ b/tests/test-copy.t	Wed Aug 29 09:59:08 2018 -0700
@@ -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 ..
--- a/tests/test-rename.t	Wed Aug 29 09:54:50 2018 -0700
+++ b/tests/test-rename.t	Wed Aug 29 09:59:08 2018 -0700
@@ -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