Patchwork D10355: rename: add --forget option and stop suggesting `hg revert` for undoing

login
register
mail settings
Submitter phabricator
Date April 9, 2021, 4:09 p.m.
Message ID <differential-rev-PHID-DREV-muo4ghnzp2o4xjedf2ib-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48672/
State Superseded
Headers show

Comments

phabricator - April 9, 2021, 4:09 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/commands.py
  tests/test-completion.t
  tests/test-copy.t

CHANGE DETAILS




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

Patch

diff --git a/tests/test-copy.t b/tests/test-copy.t
--- a/tests/test-copy.t
+++ b/tests/test-copy.t
@@ -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
 
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -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
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -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.
     """