Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 48258:c62e4397eb28
copy: recommend `--at-rev .` if target was added in parent commit
If the target file was added in the working copy parent, it's much
more likely that the user meant to use `--at-rev .` (to record the
copy/rename in the that commit) than `--force` (to replace the
just-added file by another file).
Differential Revision: https://phab.mercurial-scm.org/D11667
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 14 Oct 2021 10:58:39 -0700 |
parents | 5105a9975407 |
children | 6a454e7053a1 |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Mon Oct 18 10:14:44 2021 +0200 +++ b/mercurial/cmdutil.py Thu Oct 14 10:58:39 2021 -0700 @@ -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: