[Updated] D11667: copy: recommend `--at-rev .` if target was added in parent commit
martinvonz (Martin von Zweigbergk)
phabricator at mercurial-scm.org
Mon Oct 18 16:11:03 UTC 2021
martinvonz marked an inline comment as done.
martinvonz updated this revision to Diff 30879.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D11667?vs=30812&id=30879
BRANCH
default
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D11667/new/
REVISION DETAIL
https://phab.mercurial-scm.org/D11667
AFFECTED FILES
mercurial/cmdutil.py
tests/test-rename-rev.t
CHANGE DETAILS
diff --git a/tests/test-rename-rev.t b/tests/test-rename-rev.t
--- a/tests/test-rename-rev.t
+++ b/tests/test-rename-rev.t
@@ -42,6 +42,17 @@
d1/b
A d1/d
d1/b
+# Should get helpful message if we try to copy or rename after commit
+ $ hg cp --forget --at-rev . d1/d
+ saved backup bundle to $TESTTMP/.hg/strip-backup/3f7c325d3f9e-46f377bb-uncopy.hg
+ $ hg cp d1/b d1/d
+ d1/d: not overwriting - file already committed
+ ('hg copy --at-rev .' to record the copy in the parent of the working copy)
+ [1]
+ $ hg mv d1/b d1/d
+ d1/d: not overwriting - file already committed
+ ('hg rename --at-rev .' to record the rename in the parent of the working copy)
+ [1]
Test moved file (not copied) using 'hg cp' command
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1678,26 +1678,44 @@
if not opts[b'force']:
if already_commited:
msg = _(b'%s: not overwriting - file already committed\n')
- if after:
- flags = b'--after --force'
- else:
- flags = b'--force'
- if rename:
- hint = (
- _(
- b"('hg rename %s' to replace the file by "
- b'recording a rename)\n'
+ # Check if if the target was added in the parent and the
+ # source already existed in the grandparent.
+ looks_like_copy_in_pctx = abstarget in pctx and any(
+ abssrc in gpctx and abstarget not in gpctx
+ for gpctx in pctx.parents()
+ )
+ if looks_like_copy_in_pctx:
+ if rename:
+ hint = _(
+ b"('hg rename --at-rev .' to record the rename "
+ b"in the parent of the working copy)\n"
+ )
+ else:
+ hint = _(
+ b"('hg copy --at-rev .' to record the copy in "
+ b"the parent of the working copy)\n"
)
- % flags
- )
else:
- hint = (
- _(
- b"('hg copy %s' to replace the file by "
- b'recording a copy)\n'
+ if after:
+ flags = b'--after --force'
+ else:
+ flags = b'--force'
+ if rename:
+ hint = (
+ _(
+ b"('hg rename %s' to replace the file by "
+ b'recording a rename)\n'
+ )
+ % flags
)
- % flags
- )
+ else:
+ hint = (
+ _(
+ b"('hg copy %s' to replace the file by "
+ b'recording a copy)\n'
+ )
+ % flags
+ )
else:
msg = _(b'%s: not overwriting - file exists\n')
if rename:
To: martinvonz, #hg-reviewers
Cc: Alphare, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20211018/d7814aa2/attachment-0002.html>
More information about the Mercurial-patches
mailing list