diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5816,6 +5816,7 @@ b'resolve', [ (b'a', b'all', None, _(b'select all unresolved files')), + (b'', b'clear', None, _(b'clear resolved merge state')), (b'l', b'list', None, _(b'list state of files needing merge')), (b'm', b'mark', None, _(b'mark files as resolved')), (b'u', b'unmark', None, _(b'mark files as unresolved')), @@ -5862,6 +5863,11 @@ You can use ``set:unresolved()`` or ``set:resolved()`` to filter the list. See :hg:`help filesets` for details. + - :hg:`resolve --clear`: clear the merge state. + This is not allowed when there are unresolved files. Note that + :hg:`commit` will also clear the conflicts, so this option is primarily + useful when you cannot commit because the working copy is clean. + .. note:: Mercurial will not let you commit files with unresolved merge @@ -5883,10 +5889,12 @@ opts = pycompat.byteskwargs(opts) confirm = ui.configbool(b'commands', b'resolve.confirm') - flaglist = b'all mark unmark list no_status re_merge'.split() - all, mark, unmark, show, nostatus, remerge = [opts.get(o) for o in flaglist] - - actioncount = len(list(filter(None, [show, mark, unmark, remerge]))) + flaglist = b'all clear mark unmark list no_status re_merge'.split() + all, clear, mark, unmark, show, nostatus, remerge = [ + opts.get(o) for o in flaglist + ] + + actioncount = len(list(filter(None, [clear, show, mark, unmark, remerge]))) if actioncount > 1: raise error.Abort(_(b"too many actions specified")) elif actioncount == 0 and ui.configbool( @@ -5896,7 +5904,7 @@ raise error.Abort(_(b'no action specified'), hint=hint) if pats and all: raise error.Abort(_(b"can't specify --all and patterns")) - if not (all or pats or show or mark or unmark): + if not (all or pats or clear or show or mark or unmark): raise error.Abort( _(b'no files or directories specified'), hint=b'use --all to re-merge all unresolved files', @@ -5927,6 +5935,14 @@ uipathfn = scmutil.getuipathfn(repo) + if clear: + ms = mergemod.mergestate.read(repo) + if ms.unresolvedcount(): + raise error.Abort(_(b'unresolved merge conflicts')) + + ms.reset() + return 0 + if show: ui.pager(b'resolve') fm = ui.formatter(b'resolve', opts) diff --git a/relnotes/next b/relnotes/next --- a/relnotes/next +++ b/relnotes/next @@ -29,6 +29,10 @@ * `hg debugmergestate` output is now templated, which may be useful e.g. for IDEs that want to help the user resolve merge conflicts. + * New `hg resolve --clear` for clearing the merge state. The merge + state is normally cleared on commit. The new option can be useful + when you can't commit because the working copy is clean. + == New Experimental Features == diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -350,7 +350,7 @@ recover: verify remove: after, force, subrepos, include, exclude, dry-run rename: after, force, include, exclude, dry-run - resolve: all, list, mark, unmark, no-status, re-merge, tool, include, exclude, template + resolve: all, clear, list, mark, unmark, no-status, re-merge, tool, include, exclude, template revert: all, date, rev, no-backup, interactive, include, exclude, dry-run rollback: dry-run, force root: template diff --git a/tests/test-resolve.t b/tests/test-resolve.t --- a/tests/test-resolve.t +++ b/tests/test-resolve.t @@ -221,6 +221,31 @@ (use 'hg resolve' to resolve) [255] +test `hg resolve --clear` + $ hg up -qC 0 + $ echo quux >> file1 + $ hg up 1 + merging file1 + warning: conflicts while merging file1! (edit, then use 'hg resolve --mark') + 1 files updated, 0 files merged, 0 files removed, 1 files unresolved + use 'hg resolve' to retry unresolved file merges + [1] +aborts if there are unresolved files + $ hg resolve --clear + abort: unresolved merge conflicts + [255] +clears resolved conflicts + $ echo resolved > file1 + $ hg resolve -m file1 + (no more unresolved files) + $ hg resolve -l + R file1 + $ hg resolve --clear + $ hg resolve -l +no effect if there + $ hg resolve --clear + $ hg resolve -l + set up conflict-free merge $ hg up -qC 3