D4035: resolve: add option to warn/abort on -m with unresolved conflict markers
spectral (Kyle Lippincott)
phabricator at mercurial-scm.org
Wed Aug 1 17:58:44 EDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGbb54db4a4350: resolve: add option to warn/abort on -m with unresolved conflict markers (authored by spectral, committed by ).
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D4035?vs=9741&id=9751
REVISION DETAIL
https://phab.mercurial-scm.org/D4035
AFFECTED FILES
mercurial/commands.py
mercurial/configitems.py
mercurial/filemerge.py
tests/test-resolve.t
CHANGE DETAILS
diff --git a/tests/test-resolve.t b/tests/test-resolve.t
--- a/tests/test-resolve.t
+++ b/tests/test-resolve.t
@@ -373,4 +373,53 @@
$ hg resolve -l
+resolve -m can be configured to look for remaining conflict markers
+ $ hg up -qC 2
+ $ hg merge -q --tool=internal:merge 1
+ warning: conflicts while merging file1! (edit, then use 'hg resolve --mark')
+ warning: conflicts while merging file2! (edit, then use 'hg resolve --mark')
+ [1]
+ $ hg resolve -l
+ U file1
+ U file2
+ $ echo 'remove markers' > file1
+ $ hg --config experimental.resolve.mark-check=abort resolve -m
+ warning: the following files still have conflict markers:
+ file2
+ abort: conflict markers detected
+ (use --all to mark anyway)
+ [255]
+ $ hg resolve -l
+ U file1
+ U file2
+Try with --all from the hint
+ $ hg --config experimental.resolve.mark-check=abort resolve -m --all
+ warning: the following files still have conflict markers:
+ file2
+ (no more unresolved files)
+ $ hg resolve -l
+ R file1
+ R file2
+ $ hg resolve --unmark
+ $ hg resolve -l
+ U file1
+ U file2
+ $ hg --config experimental.resolve.mark-check=warn resolve -m
+ warning: the following files still have conflict markers:
+ file2
+ (no more unresolved files)
+ $ hg resolve -l
+ R file1
+ R file2
+If the file is already marked as resolved, we don't warn about it
+ $ hg resolve --unmark file1
+ $ hg resolve -l
+ U file1
+ R file2
+ $ hg --config experimental.resolve.mark-check=warn resolve -m
+ (no more unresolved files)
+ $ hg resolve -l
+ R file1
+ R file2
+
$ cd ..
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -916,14 +916,17 @@
_haltmerge()
# default action is 'continue', in which case we neither prompt nor halt
+def hasconflictmarkers(data):
+ return bool(re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", data,
+ re.MULTILINE))
+
def _check(repo, r, ui, tool, fcd, files):
fd = fcd.path()
unused, unused, unused, back = files
if not r and (_toolbool(ui, tool, "checkconflicts") or
'conflicts' in _toollist(ui, tool, "check")):
- if re.search("^(<<<<<<< .*|=======|>>>>>>> .*)$", fcd.data(),
- re.MULTILINE):
+ if hasconflictmarkers(fcd.data()):
r = 1
checked = False
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -931,6 +931,9 @@
default=True,
alias=[('format', 'aggressivemergedeltas')],
)
+coreconfigitem('experimental', 'resolve.mark-check',
+ default=None,
+)
coreconfigitem('server', 'bookmarks-pushkey-compat',
default=True,
)
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -35,6 +35,7 @@
error,
exchange,
extensions,
+ filemerge,
formatter,
graphmod,
hbisect,
@@ -4594,6 +4595,9 @@
runconclude = False
tocomplete = []
+ hasconflictmarkers = []
+ if mark:
+ markcheck = ui.config('experimental', 'resolve.mark-check')
for f in ms:
if not m(f):
continue
@@ -4629,6 +4633,12 @@
continue
if mark:
+ if markcheck:
+ with repo.wvfs(f) as fobj:
+ fdata = fobj.read()
+ if filemerge.hasconflictmarkers(fdata) and \
+ ms[f] != mergemod.MERGE_RECORD_RESOLVED:
+ hasconflictmarkers.append(f)
ms.mark(f, mergemod.MERGE_RECORD_RESOLVED)
elif unmark:
ms.mark(f, mergemod.MERGE_RECORD_UNRESOLVED)
@@ -4663,6 +4673,13 @@
if inst.errno != errno.ENOENT:
raise
+ if hasconflictmarkers:
+ ui.warn(_('warning: the following files still have conflict '
+ 'markers:\n ') + '\n '.join(hasconflictmarkers) + '\n')
+ if markcheck == 'abort' and not all:
+ raise error.Abort(_('conflict markers detected'),
+ hint=_('use --all to mark anyway'))
+
for f in tocomplete:
try:
# resolve file
To: spectral, #hg-reviewers
Cc: pulkit, khanchi97, mercurial-devel
More information about the Mercurial-devel
mailing list