diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -769,6 +769,38 @@ return subset +@predicate(b'conflictlocal()', safe=True) +def conflictlocal(repo, subset, x): + """The local side of the merge, if currently in an unresolved merge. + + "merge" here includes merge conflicts from e.g. 'hg rebase' or 'hg graft'. + """ + getargs(x, 0, 0, _(b"conflictlocal takes no arguments")) + from . import merge + + mergestate = merge.mergestate.read(repo) + if mergestate.active() and repo.changelog.hasnode(mergestate.local): + return subset & {repo.changelog.rev(mergestate.local)} + + return baseset() + + +@predicate(b'conflictother()', safe=True) +def conflictother(repo, subset, x): + """The other side of the merge, if currently in an unresolved merge. + + "merge" here includes merge conflicts from e.g. 'hg rebase' or 'hg graft'. + """ + getargs(x, 0, 0, _(b"conflictother takes no arguments")) + from . import merge + + mergestate = merge.mergestate.read(repo) + if mergestate.active() and repo.changelog.hasnode(mergestate.other): + return subset & {repo.changelog.rev(mergestate.other)} + + return baseset() + + @predicate(b'contains(pattern)', weight=100) def contains(repo, subset, x): """The revision's manifest contains a file matching pattern (but might not diff --git a/relnotes/next b/relnotes/next --- a/relnotes/next +++ b/relnotes/next @@ -3,6 +3,11 @@ * `hg purge`/`hg clean` can now delete ignored files instead of untracked files, with the new -i flag. + * New `conflictlocal()` and `conflictother()` revsets 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,37 @@ abort: cannot commit merge with missing files [255] + +Test conflict*() revsets + +# Bad usage + $ hg log -r 'conflictlocal(foo)' + hg: parse error: conflictlocal takes no arguments + [255] + $ hg log -r 'conflictother(foo)' + hg: parse error: conflictother 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 'conflictlocal() + conflictother()' +# 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 'conflictlocal() + conflictother()' + $ 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 'conflictlocal()' -T '{rev} {desc}\n' + 3 conflicting change to b + $ hg log -r 'conflictother()' -T '{rev} {desc}\n' + 1 commit #1