Patchwork D9835: resolve: also detect new :mergediff conflict markers

login
register
mail settings
Submitter phabricator
Date Jan. 19, 2021, 11:19 p.m.
Message ID <differential-rev-PHID-DREV-uunwancyozbfnmqxsyx2-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48146/
State Superseded
Headers show

Comments

phabricator - Jan. 19, 2021, 11:19 p.m.
martinvonz created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The conflict markers created by `:mergediff` were not detected as
  conflicts, which affects both `commands.resolve.mark-check` and
  `mergetools.<tool>.check`. This patch fixes that.
  
  The new regex it uses for finding conflict markers is less restrictive
  because it `:mergediff` doesn't follow the `<<<<<<<` and `>>>>>>>`
  lines by a space (and a description). Hopefully lines like that don't
  give too many false positives. We can add back the space and make
  `:mergediff` add trailing spaces if it turns out to be a
  problem. OTOH, there will always be some false positives and we have
  ways of overriding the checks already.
  
  This patch can go onto the default or stable branch, depending on how
  much we care about an experimental feature.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/filemerge.py
  tests/test-resolve.t

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-patches, 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
@@ -344,6 +344,24 @@ 
   $ hg resolve -l
   R file1
   R file2
+Test with :mergediff conflict markers
+  $ hg resolve --unmark
+  $ hg resolve --re-merge -t :mergediff file2
+  merging file2
+  warning: conflicts while merging file2! (edit, then use 'hg resolve --mark')
+  [1]
+  $ hg resolve -l
+  U file1
+  U file2
+  $ hg --config commands.resolve.mark-check=abort resolve -m
+  warning: the following files still have conflict markers:
+    file2
+  abort: conflict markers detected
+  (use --all to mark anyway)
+  [20]
+  $ hg resolve -l
+  U file1
+  U file2
 Test option value 'warn'
   $ hg resolve --unmark
   $ hg resolve -l
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -1195,7 +1195,11 @@ 
 
 def hasconflictmarkers(data):
     return bool(
-        re.search(b"^(<<<<<<< .*|=======|>>>>>>> .*)$", data, re.MULTILINE)
+        re.search(
+            br"^(<<<<<<<.*|=======|------- .*|\+\+\+\+\+\+\+ .*|>>>>>>>.*)$",
+            data,
+            re.MULTILINE,
+        )
     )