diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1858,6 +1858,27 @@ return subset & ps +@predicate(b'conflictparents()', safe=True) +def parents(repo, subset, x): + """ + The two parents of the merge, if currently in an unresolved merge. + + If "merge" here includes merge conflicts from e.g. 'hg rebase' or + 'hg graft'. + """ + getargs(x, 0, 0, _(b"conflictparents takes no arguments")) + from . import merge + + mergestate = merge.mergestate.read(repo) + revs = set() + if mergestate.active(): + for n in (mergestate.local, mergestate.other): + if repo.changelog.hasnode(n): + revs.add(repo.changelog.rev(n)) + + return subset & revs + + def _phase(repo, subset, *targets): """helper to select all rev in phases""" return repo._phasecache.getrevset(repo, targets, subset) diff --git a/relnotes/next b/relnotes/next --- a/relnotes/next +++ b/relnotes/next @@ -1,5 +1,9 @@ == New Features == + * New `conflictparents()` revset returns the commits that are being + merged, when there are conflicts. Also works for conflicts caused + by e.g. `hg graft`. + == New Experimental Features == diff --git a/tests/test-merge4.t b/tests/test-merge4.t --- a/tests/test-merge4.t +++ b/tests/test-merge4.t @@ -23,3 +23,33 @@ abort: cannot commit merge with missing files [255] + +Test conflictparents() revset + +# Bad usage + $ hg log -r 'conflictparents(foo)' + hg: parse error: conflictparents takes no arguments + [255] + $ hg co -C . + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved +# No merge parents when not merging + $ hg log -r 'conflictparents()' +# No merge parents when there is no conflict + $ hg merge 1 + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + (branch merge, don't forget to commit) + $ hg log -r 'conflictparents()' + $ hg co -C . + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + $ echo conflict > b + $ hg ci -Aqm 'conflicting change to b' + $ hg merge 1 + merging b + warning: conflicts while merging b! (edit, then use 'hg resolve --mark') + 0 files updated, 0 files merged, 0 files removed, 1 files unresolved + use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon + [1] +# Shows merge parents when there is a conflict + $ hg log -r 'conflictparents()' -T '{rev} {desc}\n' + 1 commit #1 + 3 conflicting change to b