Patchwork [STABLE] localrepo.commit: check all files for resolve state (issue4972)

login
register
mail settings
Submitter Siddharth Agarwal
Date Dec. 1, 2015, 12:33 a.m.
Message ID <70219d705c72a9ae172a.1448930003@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11694/
State Accepted
Headers show

Comments

Siddharth Agarwal - Dec. 1, 2015, 12:33 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1448929888 28800
#      Mon Nov 30 16:31:28 2015 -0800
# Branch stable
# Node ID 70219d705c72a9ae172a41d13a07535c0a5aa7ca
# Parent  c3112b1b6a5b681ead90d8f627d580502b11336e
# Available At http://42.netv6.net/sid0-wip/hg/
#              hg pull http://42.netv6.net/sid0-wip/hg/ -r 70219d705c72
localrepo.commit: check all files for resolve state (issue4972)

Previously we were only checking modified files for their resolve state. But a
file might be unresolved yet not in the modified state. Handle all such cases
properly.
Pierre-Yves David - Dec. 1, 2015, 2:57 a.m.
On 11/30/2015 04:33 PM, Siddharth Agarwal wrote:
> # HG changeset patch
> # User Siddharth Agarwal <sid0@fb.com>
> # Date 1448929888 28800
> #      Mon Nov 30 16:31:28 2015 -0800
> # Branch stable
> # Node ID 70219d705c72a9ae172a41d13a07535c0a5aa7ca
> # Parent  c3112b1b6a5b681ead90d8f627d580502b11336e
> # Available At http://42.netv6.net/sid0-wip/hg/
> #              hg pull http://42.netv6.net/sid0-wip/hg/ -r 70219d705c72
> localrepo.commit: check all files for resolve state (issue4972)

The fix is so simple that I'm almost shocked.

Pushed to the clowncopter with many thanks (and check-code regards)
Siddharth Agarwal - Dec. 1, 2015, 7:33 p.m.
+mpm as requested

On 11/30/15 18:57, Pierre-Yves David wrote:
>
>
> On 11/30/2015 04:33 PM, Siddharth Agarwal wrote:
>> # HG changeset patch
>> # User Siddharth Agarwal <sid0@fb.com>
>> # Date 1448929888 28800
>> #      Mon Nov 30 16:31:28 2015 -0800
>> # Branch stable
>> # Node ID 70219d705c72a9ae172a41d13a07535c0a5aa7ca
>> # Parent  c3112b1b6a5b681ead90d8f627d580502b11336e
>> # Available At http://42.netv6.net/sid0-wip/hg/
>> #              hg pull http://42.netv6.net/sid0-wip/hg/ -r 70219d705c72
>> localrepo.commit: check all files for resolve state (issue4972)
>
> The fix is so simple that I'm almost shocked.
>
> Pushed to the clowncopter with many thanks (and check-code regards)
>

Patch

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1556,19 +1556,12 @@  class localrepository(object):
             if merge and cctx.deleted():
                 raise error.Abort(_("cannot commit merge with missing files"))
 
-            unresolved, driverresolved = False, False
             ms = mergemod.mergestate(self)
-            for f in status.modified:
-                if f in ms:
-                    if ms[f] == 'u':
-                        unresolved = True
-                    elif ms[f] == 'd':
-                        driverresolved = True
 
-            if unresolved:
+            if list(ms.unresolved()):
                 raise error.Abort(_('unresolved merge conflicts '
                                     '(see "hg help resolve")'))
-            if driverresolved or ms.mdstate() != 's':
+            if ms.mdstate() != 's' or list(ms.driverresolved()):
                 raise error.Abort(_('driver-resolved merge conflicts'),
                                   hint=_('run "hg resolve --all" to resolve'))
 
diff --git a/tests/test-commit-unresolved.t b/tests/test-commit-unresolved.t
--- a/tests/test-commit-unresolved.t
+++ b/tests/test-commit-unresolved.t
@@ -43,4 +43,25 @@  Mark the conflict as resolved and commit
   (no more unresolved files)
   $ hg commit -m "Merged"
 
+Test that if a file is removed but not marked resolved, the commit still fails
+(issue4972)
+
+  $ hg up .^
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg merge 2
+  merging A
+  warning: conflicts while merging A! (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 or 'hg update -C .' to abandon
+  [1]
+  $ hg rm --force A
+  $ hg commit -m merged
+  abort: unresolved merge conflicts (see "hg help resolve")
+  [255]
+
+  $ hg resolve -ma
+  (no more unresolved files)
+  $ hg commit -m merged
+  created new head
+
   $ cd ..