comparison 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
comparison
equal deleted inserted replaced
48257:2f7caef017d9 48258:c62e4397eb28
1676 1676
1677 if not after and exists or after and already_commited: 1677 if not after and exists or after and already_commited:
1678 if not opts[b'force']: 1678 if not opts[b'force']:
1679 if already_commited: 1679 if already_commited:
1680 msg = _(b'%s: not overwriting - file already committed\n') 1680 msg = _(b'%s: not overwriting - file already committed\n')
1681 if after: 1681 # Check if if the target was added in the parent and the
1682 flags = b'--after --force' 1682 # source already existed in the grandparent.
1683 looks_like_copy_in_pctx = abstarget in pctx and any(
1684 abssrc in gpctx and abstarget not in gpctx
1685 for gpctx in pctx.parents()
1686 )
1687 if looks_like_copy_in_pctx:
1688 if rename:
1689 hint = _(
1690 b"('hg rename --at-rev .' to record the rename "
1691 b"in the parent of the working copy)\n"
1692 )
1693 else:
1694 hint = _(
1695 b"('hg copy --at-rev .' to record the copy in "
1696 b"the parent of the working copy)\n"
1697 )
1683 else: 1698 else:
1684 flags = b'--force' 1699 if after:
1685 if rename: 1700 flags = b'--after --force'
1686 hint = ( 1701 else:
1687 _( 1702 flags = b'--force'
1688 b"('hg rename %s' to replace the file by " 1703 if rename:
1689 b'recording a rename)\n' 1704 hint = (
1705 _(
1706 b"('hg rename %s' to replace the file by "
1707 b'recording a rename)\n'
1708 )
1709 % flags
1690 ) 1710 )
1691 % flags 1711 else:
1692 ) 1712 hint = (
1693 else: 1713 _(
1694 hint = ( 1714 b"('hg copy %s' to replace the file by "
1695 _( 1715 b'recording a copy)\n'
1696 b"('hg copy %s' to replace the file by " 1716 )
1697 b'recording a copy)\n' 1717 % flags
1698 ) 1718 )
1699 % flags
1700 )
1701 else: 1719 else:
1702 msg = _(b'%s: not overwriting - file exists\n') 1720 msg = _(b'%s: not overwriting - file exists\n')
1703 if rename: 1721 if rename:
1704 hint = _( 1722 hint = _(
1705 b"('hg rename --after' to record the rename)\n" 1723 b"('hg rename --after' to record the rename)\n"