Patchwork D8289: resolve: add a --clear option for clearing the merge state

login
register
mail settings
Submitter phabricator
Date March 13, 2020, 9:21 p.m.
Message ID <differential-rev-PHID-DREV-2kn5yuvr3wzb2ykwn3zp-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45775/
State New
Headers show

Comments

phabricator - March 13, 2020, 9:21 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8289

AFFECTED FILES
  mercurial/commands.py
  relnotes/next
  tests/test-completion.t
  tests/test-resolve.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - March 19, 2020, 8:30 a.m.
pulkit added a comment.


  I like the idea. IIRC, Ryan from FB hit similar issues in a sprint some years ago and came up with `hg up --finish` or something like that.
  
  Maybe we should not let user clear the mergestate and suggest `continue/<cmd-name> --continue` if it's not result of update command. Thoughts?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8289/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8289

To: martinvonz, #hg-reviewers
Cc: pulkit, mercurial-devel
phabricator - March 19, 2020, 11:43 p.m.
marmoute added a comment.


  In D8289#124009 <https://phab.mercurial-scm.org/D8289#124009>, @pulkit wrote:
  
  > I like the idea. IIRC, Ryan from FB hit similar issues in a sprint some years ago and came up with `hg up --finish` or something like that.
  > Maybe we should not let user clear the mergestate and suggest `continue/<cmd-name> --continue` if it's not result of update command. Thoughts?
  
  Ho, that's a good idea. It looks like `hg update --merge` is the only command that do not have `--continue` support. So instead of adding a whole new flag and action to this exception, removing the exception seems like a better move. What do you think @martinvonz ?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8289/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8289

To: martinvonz, #hg-reviewers
Cc: marmoute, pulkit, mercurial-devel
phabricator - March 19, 2020, 11:55 p.m.
martinvonz added a comment.
martinvonz planned changes to this revision.


  In D8289#124060 <https://phab.mercurial-scm.org/D8289#124060>, @marmoute wrote:
  
  > In D8289#124009 <https://phab.mercurial-scm.org/D8289#124009>, @pulkit wrote:
  >
  >> I like the idea. IIRC, Ryan from FB hit similar issues in a sprint some years ago and came up with `hg up --finish` or something like that.
  >> Maybe we should not let user clear the mergestate and suggest `continue/<cmd-name> --continue` if it's not result of update command. Thoughts?
  >
  > Ho, that's a good idea. It looks like `hg update --merge` is the only command that do not have `--continue` support. So instead of adding a whole new flag and action to this exception, removing the exception seems like a better move. What do you think @martinvonz ?
  
  Yeah, I agree (sorry, was busy with other stuff today). It should be easy to change this patch from `hg resolve --clear` to `hg update --continue`. I might add the `hg continue` support as separate patch on top.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8289/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8289

To: martinvonz, #hg-reviewers
Cc: marmoute, pulkit, mercurial-devel

Patch

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
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/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/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)