changeset 46886:37f49d462394

rename: add --forget option and stop suggesting `hg revert` for undoing Differential Revision: https://phab.mercurial-scm.org/D10355
author Martin von Zweigbergk <martinvonz@google.com>
date Fri, 09 Apr 2021 08:46:40 -0700
parents fc8a5c9ecee0
children 6d5a26e94d9e
files mercurial/commands.py tests/test-completion.t tests/test-copy.t
diffstat 3 files changed, 44 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Fri Apr 09 11:32:19 2021 -0400
+++ b/mercurial/commands.py	Fri Apr 09 08:46:40 2021 -0700
@@ -2413,7 +2413,8 @@
 
     To undo marking a destination file as copied, use --forget. With that
     option, all given (positional) arguments are unmarked as copies. The
-    destination file(s) will be left in place (still tracked).
+    destination file(s) will be left in place (still tracked). Note that
+    :hg:`copy --forget` behaves the same way as :hg:`rename --forget`.
 
     This command takes effect with the next commit by default.
 
@@ -5914,6 +5915,7 @@
 @command(
     b'rename|move|mv',
     [
+        (b'', b'forget', None, _(b'unmark a destination file as renamed')),
         (b'A', b'after', None, _(b'record a rename that has already occurred')),
         (
             b'',
@@ -5945,8 +5947,13 @@
     exist in the working directory. If invoked with -A/--after, the
     operation is recorded, but no copying is performed.
 
-    This command takes effect at the next commit. To undo a rename
-    before that, see :hg:`revert`.
+    To undo marking a destination file as renamed, use --forget. With that
+    option, all given (positional) arguments are unmarked as renames. The
+    destination file(s) will be left in place (still tracked). The source
+    file(s) will not be restored. Note that :hg:`rename --forget` behaves
+    the same way as :hg:`copy --forget`.
+
+    This command takes effect with the next commit by default.
 
     Returns 0 on success, 1 if errors are encountered.
     """
--- a/tests/test-completion.t	Fri Apr 09 11:32:19 2021 -0400
+++ b/tests/test-completion.t	Fri Apr 09 08:46:40 2021 -0700
@@ -361,7 +361,7 @@
   push: force, rev, bookmark, all-bookmarks, branch, new-branch, pushvars, publish, ssh, remotecmd, insecure
   recover: verify
   remove: after, force, subrepos, include, exclude, dry-run
-  rename: after, at-rev, force, include, exclude, dry-run
+  rename: forget, after, at-rev, force, include, exclude, dry-run
   resolve: all, list, mark, unmark, no-status, re-merge, tool, include, exclude, template
   revert: all, date, rev, no-backup, interactive, include, exclude, dry-run
   rollback: dry-run, force
--- a/tests/test-copy.t	Fri Apr 09 11:32:19 2021 -0400
+++ b/tests/test-copy.t	Fri Apr 09 08:46:40 2021 -0700
@@ -277,19 +277,25 @@
   $ rm baz xyzzy
 
 
-Test unmarking copy of a single file
+Test unmarking copy/rename of a single file
 
 # Set up by creating a copy
   $ hg cp bar baz
-# Test uncopying a non-existent file
+# Test unmarking as copy a non-existent file
   $ hg copy --forget non-existent
   non-existent: $ENOENT$
-# Test uncopying an tracked but unrelated file
+  $ hg rename --forget non-existent
+  non-existent: $ENOENT$
+# Test unmarking as copy an tracked but unrelated file
   $ hg copy --forget foo
   foo: not unmarking as copy - file is not marked as copied
-# Test uncopying a copy source
+  $ hg rename --forget foo
+  foo: not unmarking as copy - file is not marked as copied
+# Test unmarking as copy a copy source
   $ hg copy --forget bar
   bar: not unmarking as copy - file is not marked as copied
+  $ hg rename --forget bar
+  bar: not unmarking as copy - file is not marked as copied
 # baz should still be marked as a copy
   $ hg st -C
   A baz
@@ -298,17 +304,38 @@
   $ hg copy --forget baz
   $ hg st -C
   A baz
-# Test uncopy with matching an non-matching patterns
+  $ rm bar
+  $ hg rename --after bar baz
+  $ hg st -C
+  A baz
+    bar
+  R bar
+  $ hg rename --forget baz
+  $ hg st -C
+  A baz
+  R bar
+  $ hg revert bar
+# Test unmarking as copy with matching an non-matching patterns
   $ hg cp bar baz --after
   $ hg copy --forget bar baz
   bar: not unmarking as copy - file is not marked as copied
+  $ hg cp bar baz --after
+  $ hg rename --forget bar baz
+  bar: not unmarking as copy - file is not marked as copied
   $ hg st -C
   A baz
-# Test uncopy with no exact matches
+# Test unmarking as copy with no exact matches
   $ hg cp bar baz --after
   $ hg copy --forget .
   $ hg st -C
   A baz
+  $ hg cp bar baz --after
+  $ hg st -C
+  A baz
+    bar
+  $ hg rename --forget .
+  $ hg st -C
+  A baz
   $ hg forget baz
   $ rm baz