comparison mercurial/commands.py @ 38793:6c8e3c847977

resolve: add option to warn/abort on -m with unresolved conflict markers When a user is dropped out of Mercurial to a terminal to resolve files, we emit messages like: conflicts while merging file1! (edit, then use 'hg resolve --mark') conflicts while merging file2! (edit, then use 'hg resolve --mark') We don't mention a file name in the hint, so some users might do something like `$EDITOR file1; hg resolve --mark`, see that it says "(no more unresolved files)" and forget to deal with file2 before running the next command. Even if we did mention a file name in the hint, it's too easy to forget it (maybe the merge spans a couple days or something). This option lets us inform the user that they might have missed something. In the scenario above, the output would be something like: warning: the following files still have conflict markers: file2 (no more unresolved files) Differential Revision: https://phab.mercurial-scm.org/D4035
author Kyle Lippincott <spectral@google.com>
date Thu, 26 Jul 2018 17:11:03 -0700
parents e7aa113b14f7
children f8732e33bcbc
comparison
equal deleted inserted replaced
38792:afb442f58cbf 38793:6c8e3c847977
33 discovery, 33 discovery,
34 encoding, 34 encoding,
35 error, 35 error,
36 exchange, 36 exchange,
37 extensions, 37 extensions,
38 filemerge,
38 formatter, 39 formatter,
39 graphmod, 40 graphmod,
40 hbisect, 41 hbisect,
41 help, 42 help,
42 hg, 43 hg,
4592 ret = 0 4593 ret = 0
4593 didwork = False 4594 didwork = False
4594 runconclude = False 4595 runconclude = False
4595 4596
4596 tocomplete = [] 4597 tocomplete = []
4598 hasconflictmarkers = []
4599 if mark:
4600 markcheck = ui.config('experimental', 'resolve.mark-check')
4597 for f in ms: 4601 for f in ms:
4598 if not m(f): 4602 if not m(f):
4599 continue 4603 continue
4600 4604
4601 didwork = True 4605 didwork = True
4627 ui.warn(_('%s: path conflict must be resolved manually\n') 4631 ui.warn(_('%s: path conflict must be resolved manually\n')
4628 % f) 4632 % f)
4629 continue 4633 continue
4630 4634
4631 if mark: 4635 if mark:
4636 if markcheck:
4637 with repo.wvfs(f) as fobj:
4638 fdata = fobj.read()
4639 if filemerge.hasconflictmarkers(fdata) and \
4640 ms[f] != mergemod.MERGE_RECORD_RESOLVED:
4641 hasconflictmarkers.append(f)
4632 ms.mark(f, mergemod.MERGE_RECORD_RESOLVED) 4642 ms.mark(f, mergemod.MERGE_RECORD_RESOLVED)
4633 elif unmark: 4643 elif unmark:
4634 ms.mark(f, mergemod.MERGE_RECORD_UNRESOLVED) 4644 ms.mark(f, mergemod.MERGE_RECORD_UNRESOLVED)
4635 else: 4645 else:
4636 # backup pre-resolve (merge uses .orig for its own purposes) 4646 # backup pre-resolve (merge uses .orig for its own purposes)
4660 util.rename(a + ".resolve", 4670 util.rename(a + ".resolve",
4661 scmutil.origpath(ui, repo, a)) 4671 scmutil.origpath(ui, repo, a))
4662 except OSError as inst: 4672 except OSError as inst:
4663 if inst.errno != errno.ENOENT: 4673 if inst.errno != errno.ENOENT:
4664 raise 4674 raise
4675
4676 if hasconflictmarkers:
4677 ui.warn(_('warning: the following files still have conflict '
4678 'markers:\n ') + '\n '.join(hasconflictmarkers) + '\n')
4679 if markcheck == 'abort' and not all:
4680 raise error.Abort(_('conflict markers detected'),
4681 hint=_('use --all to mark anyway'))
4665 4682
4666 for f in tocomplete: 4683 for f in tocomplete:
4667 try: 4684 try:
4668 # resolve file 4685 # resolve file
4669 overrides = {('ui', 'forcemerge'): opts.get('tool', '')} 4686 overrides = {('ui', 'forcemerge'): opts.get('tool', '')}