Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 30151:381293e1135e
copy: distinguish "file exists" cases and add a hint (BC)
Users that want to add a copy record to an existing commit with 'hg
commit --amend' should be guided towards this workflow, rather than
reaching for some sort of uncommit-recommit flow. As part of this,
distinguish in the top-line error message whether the file merely
already exists (untracked) on disk or the file already exists in
history.
The full list of copy and rename cases and how they interact with
flags are listed below:
target exists --after --force | action
n n * | copy
n y * | (1)
untracked n n | (4) NEWHINT
untracked n y | (3)
untracked y * | (2)
y n n | (4) NEWHINT
y n y | (3)
y y n | (2)
y y y | (3)
deleted n n | copy
deleted n y | (3)
deleted y n | (1)
deleted y y | (1)
* = don't care
(1) <src>: not recording move - <target> does not exist
(2) preserve target contents
(3) replace target contents
(4) <target>: not overwriting - file {exists,already committed}
Credit to Kevin for wholly rewriting my table to cover more cases we
discovered at the sprint.
I think this change gets the hints correct in all cases, but I'd
appreciate close inspection of the test cases to make sure I haven't
gotten turned around in here.
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 19 Sep 2016 17:15:39 -0400 |
parents | 3dcaf1c4e90d |
children | 144d8fe266d9 |
comparison
equal
deleted
inserted
replaced
30150:c0410814002f | 30151:381293e1135e |
---|---|
644 exists = False | 644 exists = False |
645 samefile = True | 645 samefile = True |
646 | 646 |
647 if not after and exists or after and state in 'mn': | 647 if not after and exists or after and state in 'mn': |
648 if not opts['force']: | 648 if not opts['force']: |
649 ui.warn(_('%s: not overwriting - file exists\n') % | 649 if state in 'mn': |
650 reltarget) | 650 msg = _('%s: not overwriting - file already committed\n') |
651 if after: | |
652 flags = '--after --force' | |
653 else: | |
654 flags = '--force' | |
655 if rename: | |
656 hint = _('(hg rename %s to replace the file by ' | |
657 'recording a rename)\n') % flags | |
658 else: | |
659 hint = _('(hg copy %s to replace the file by ' | |
660 'recording a copy)\n') % flags | |
661 else: | |
662 msg = _('%s: not overwriting - file exists\n') | |
663 if rename: | |
664 hint = _('(hg rename --after to record the rename)\n') | |
665 else: | |
666 hint = _('(hg copy --after to record the copy)\n') | |
667 ui.warn(msg % reltarget) | |
668 ui.warn(hint) | |
651 return | 669 return |
652 | 670 |
653 if after: | 671 if after: |
654 if not exists: | 672 if not exists: |
655 if rename: | 673 if rename: |