On its own, it's not useful, but the next commit will add an hgrc
config option to make it mandatory.
There is no short option, as -r almost always means --rev and this
option doesn't seem like it would be so common as to mandate a short
option.
pulkit |
hg-reviewers |
On its own, it's not useful, but the next commit will add an hgrc
config option to make it mandatory.
There is no short option, as -r almost always means --rev and this
option doesn't seem like it would be so common as to mandate a short
option.
Lint Skipped |
Unit Tests Skipped |
Thanks for accepting (some of) my other changes.
I added a couple of simple tests. I could add one for the hint, but I figured it's probably not worth it?
I added a couple of simple tests. I could add one for the hint, but I figured it's probably not worth it?
I *think* each case is worth a test and help us increasing code coverage.
Path | Packages | |||
---|---|---|---|---|
M | mercurial/commands.py (22 lines) | |||
M | tests/test-completion.t (2 lines) | |||
M | tests/test-resolve.t (12 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Valentin Gatien-Baron | Aug 26 2018, 3:52 PM |
Status | Author | Revision | |
---|---|---|---|
Closed | valentin.gatienbaron | ||
Closed | valentin.gatienbaron | ||
Closed | valentin.gatienbaron |
with repo.wlock(False): | with repo.wlock(False): | ||||
return cmdutil.copy(ui, repo, pats, opts, rename=True) | return cmdutil.copy(ui, repo, pats, opts, rename=True) | ||||
@command('resolve', | @command('resolve', | ||||
[('a', 'all', None, _('select all unresolved files')), | [('a', 'all', None, _('select all unresolved files')), | ||||
('l', 'list', None, _('list state of files needing merge')), | ('l', 'list', None, _('list state of files needing merge')), | ||||
('m', 'mark', None, _('mark files as resolved')), | ('m', 'mark', None, _('mark files as resolved')), | ||||
('u', 'unmark', None, _('mark files as unresolved')), | ('u', 'unmark', None, _('mark files as unresolved')), | ||||
('n', 'no-status', None, _('hide status prefix'))] | ('n', 'no-status', None, _('hide status prefix')), | ||||
('', 're-merge', None, _('re-merge files'))] | |||||
+ mergetoolopts + walkopts + formatteropts, | + mergetoolopts + walkopts + formatteropts, | ||||
_('[OPTION]... [FILE]...'), | _('[OPTION]... [FILE]...'), | ||||
inferrepo=True) | inferrepo=True) | ||||
def resolve(ui, repo, *pats, **opts): | def resolve(ui, repo, *pats, **opts): | ||||
"""redo merges or set/view the merge status of files | """redo merges or set/view the merge status of files | ||||
Merges with unresolved conflicts are often the result of | Merges with unresolved conflicts are often the result of | ||||
non-interactive merging using the ``internal:merge`` configuration | non-interactive merging using the ``internal:merge`` configuration | ||||
setting, or a command-line merge tool like ``diff3``. The resolve | setting, or a command-line merge tool like ``diff3``. The resolve | ||||
command is used to manage the files involved in a merge, after | command is used to manage the files involved in a merge, after | ||||
:hg:`merge` has been run, and before :hg:`commit` is run (i.e. the | :hg:`merge` has been run, and before :hg:`commit` is run (i.e. the | ||||
working directory must have two parents). See :hg:`help | working directory must have two parents). See :hg:`help | ||||
merge-tools` for information on configuring merge tools. | merge-tools` for information on configuring merge tools. | ||||
The resolve command can be used in the following ways: | The resolve command can be used in the following ways: | ||||
- :hg:`resolve [--tool TOOL] FILE...`: attempt to re-merge the specified | - :hg:`resolve [--re-merge] [--tool TOOL] FILE...`: attempt to re-merge | ||||
files, discarding any previous merge attempts. Re-merging is not | the specified files, discarding any previous merge attempts. Re-merging | ||||
performed for files already marked as resolved. Use ``--all/-a`` | is not performed for files already marked as resolved. Use ``--all/-a`` | ||||
to select all unresolved files. ``--tool`` can be used to specify | to select all unresolved files. ``--tool`` can be used to specify | ||||
the merge tool used for the given files. It overrides the HGMERGE | the merge tool used for the given files. It overrides the HGMERGE | ||||
environment variable and your configuration files. Previous file | environment variable and your configuration files. Previous file | ||||
contents are saved with a ``.orig`` suffix. | contents are saved with a ``.orig`` suffix. | ||||
- :hg:`resolve -m [FILE]`: mark a file as having been resolved | - :hg:`resolve -m [FILE]`: mark a file as having been resolved | ||||
(e.g. after having manually fixed-up the files). The default is | (e.g. after having manually fixed-up the files). The default is | ||||
to mark all unresolved files. | to mark all unresolved files. | ||||
conflicts. You must use :hg:`resolve -m ...` before you can | conflicts. You must use :hg:`resolve -m ...` before you can | ||||
commit after a conflicting merge. | commit after a conflicting merge. | ||||
Returns 0 on success, 1 if any files fail a resolve attempt. | Returns 0 on success, 1 if any files fail a resolve attempt. | ||||
""" | """ | ||||
opts = pycompat.byteskwargs(opts) | opts = pycompat.byteskwargs(opts) | ||||
confirm = ui.configbool('commands', 'resolve.confirm') | confirm = ui.configbool('commands', 'resolve.confirm') | ||||
flaglist = 'all mark unmark list no_status'.split() | flaglist = 'all mark unmark list no_status re_merge'.split() | ||||
all, mark, unmark, show, nostatus = \ | all, mark, unmark, show, nostatus, remerge = \ | ||||
[opts.get(o) for o in flaglist] | [opts.get(o) for o in flaglist] | ||||
if len(list(filter(None, [show, mark, unmark]))) > 1: | if len(list(filter(None, [show, mark, unmark, remerge]))) > 1: | ||||
raise error.Abort(_("too many options specified")) | raise error.Abort(_("too many options specified")) | ||||
if pats and all: | if pats and all: | ||||
raise error.Abort(_("can't specify --all and patterns")) | raise error.Abort(_("can't specify --all and patterns")) | ||||
if not (all or pats or show or mark or unmark): | if not (all or pats or show or mark or unmark): | ||||
raise error.Abort(_('no files or directories specified'), | raise error.Abort(_('no files or directories specified'), | ||||
hint=('use --all to re-merge all unresolved files')) | hint=('use --all to re-merge all unresolved files')) | ||||
if confirm: | if confirm: | ||||
if not didwork and pats: | if not didwork and pats: | ||||
hint = None | hint = None | ||||
if not any([p for p in pats if p.find(':') >= 0]): | if not any([p for p in pats if p.find(':') >= 0]): | ||||
pats = ['path:%s' % p for p in pats] | pats = ['path:%s' % p for p in pats] | ||||
m = scmutil.match(wctx, pats, opts) | m = scmutil.match(wctx, pats, opts) | ||||
for f in ms: | for f in ms: | ||||
if not m(f): | if not m(f): | ||||
continue | continue | ||||
flags = ''.join(['-%s ' % o[0:1] for o in flaglist | def flag(o): | ||||
if opts.get(o)]) | if o == 're_merge': | ||||
return '--re-merge ' | |||||
return '-%s ' % o[0:1] | |||||
flags = ''.join([flag(o) for o in flaglist if opts.get(o)]) | |||||
hint = _("(try: hg resolve %s%s)\n") % ( | hint = _("(try: hg resolve %s%s)\n") % ( | ||||
flags, | flags, | ||||
' '.join(pats)) | ' '.join(pats)) | ||||
break | break | ||||
ui.warn(_("arguments do not match paths that need resolving\n")) | ui.warn(_("arguments do not match paths that need resolving\n")) | ||||
if hint: | if hint: | ||||
ui.warn(hint) | ui.warn(hint) | ||||
elif ms.mergedriver and ms.mdstate() != 's': | elif ms.mergedriver and ms.mdstate() != 's': |
locate: rev, print0, fullpath, include, exclude | locate: rev, print0, fullpath, include, exclude | ||||
manifest: rev, all, template | manifest: rev, all, template | ||||
outgoing: force, rev, newest-first, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos | outgoing: force, rev, newest-first, bookmarks, branch, patch, git, limit, no-merges, stat, graph, style, template, ssh, remotecmd, insecure, subrepos | ||||
parents: rev, style, template | parents: rev, style, template | ||||
paths: template | paths: template | ||||
phase: public, draft, secret, force, rev | phase: public, draft, secret, force, rev | ||||
recover: | recover: | ||||
rename: after, force, include, exclude, dry-run | rename: after, force, include, exclude, dry-run | ||||
resolve: all, list, mark, unmark, no-status, tool, include, exclude, template | resolve: all, list, mark, unmark, no-status, re-merge, tool, include, exclude, template | ||||
revert: all, date, rev, no-backup, interactive, include, exclude, dry-run | revert: all, date, rev, no-backup, interactive, include, exclude, dry-run | ||||
rollback: dry-run, force | rollback: dry-run, force | ||||
root: | root: | ||||
tag: force, local, rev, remove, edit, message, date, user | tag: force, local, rev, remove, edit, message, date, user | ||||
tags: template | tags: template | ||||
tip: patch, git, style, template | tip: patch, git, style, template | ||||
unbundle: update | unbundle: update | ||||
verify: | verify: |
$ hg resolve -l | $ hg resolve -l | ||||
U file1 | U file1 | ||||
U file2 | U file2 | ||||
$ hg --config commands.resolve.mark-check=none resolve -m | $ hg --config commands.resolve.mark-check=none resolve -m | ||||
(no more unresolved files) | (no more unresolved files) | ||||
$ hg resolve -l | $ hg resolve -l | ||||
R file1 | R file1 | ||||
R file2 | R file2 | ||||
Testing the --re-merge flag | |||||
$ hg resolve --unmark file1 | |||||
$ hg resolve -l | |||||
U file1 | |||||
R file2 | |||||
$ hg resolve --mark --re-merge | |||||
abort: too many options specified | |||||
[255] | |||||
$ hg resolve --re-merge --all | |||||
merging file1 | |||||
warning: conflicts while merging file1! (edit, then use 'hg resolve --mark') | |||||
[1] | |||||
$ cd .. | $ cd .. | ||||
====================================================== | ====================================================== | ||||
Test 'hg resolve' confirm config option functionality | | Test 'hg resolve' confirm config option functionality | | ||||
====================================================== | ====================================================== | ||||
$ cat >> $HGRCPATH << EOF | $ cat >> $HGRCPATH << EOF | ||||
> [extensions] | > [extensions] |