rebase: add :abort merge tool

Summary: This adds a merge tool to only rebase if there aren't conflicts, which I think will be widely useful. It's for IMM only at the moment.

Reviewed By: DurhamG, quark-zju

Differential Revision: D8493065

fbshipit-source-id: 32ccc0e53af27d275a56bcac80861a421d7abfc6
This commit is contained in:
Phil Cohen 2018-06-19 20:13:13 -07:00 committed by Facebook Github Bot
parent 72c3d8afc1
commit 6c605e4a52
4 changed files with 76 additions and 1 deletions

View File

@ -1022,6 +1022,12 @@ def rebase(ui, repo, templ=None, **opts):
)
rbsrt.inmemory = False
return _origrebase(ui, repo, rbsrt, **opts)
except error.AbortMergeToolError as e:
ui.status(_("%s; exiting.\n") % e)
clearstatus(repo)
mergemod.mergestate.clean(repo)
if repo.currenttransaction():
repo.currenttransaction().abort()
else:
return _origrebase(ui, repo, rbsrt, **opts)

View File

@ -409,3 +409,7 @@ class InMemoryMergeConflictsError(Exception):
"""Exception raised when merge conflicts arose during an in-memory merge."""
__bytes__ = _tobytes
class AbortMergeToolError(Abort):
"""User specified :abort and there was a merge conflict; abort the merge."""

View File

@ -247,6 +247,18 @@ def _matcheol(file, back):
util.writefile(file, newdata)
@internaltool("abort", nomerge)
def _iabort(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
if fcd.changectx().isinmemory():
raise error.AbortMergeToolError(
_("hit merge conflicts, and --tool :abort passed")
)
else:
# Support coming soon; it's tricker to do without IMM and has to be
# implemented per-command.
raise error.Abort(_("--tool :abort only works with in-memory merge"))
@internaltool("prompt", nomerge)
def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
"""Asks the user which of the local `p1()` or the other `p2()` version to
@ -258,7 +270,7 @@ def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
# conflicts.
if fcd.changectx().isinmemory():
raise error.InMemoryMergeConflictsError(
"in-memory merge does not " "support file conflicts"
"in-memory merge does not support file conflicts"
)
prompts = partextras(labels)

View File

@ -0,0 +1,53 @@
Tests the :abort merge tool
$ newrepo
$ enable rebase fbamend morestatus
$ setconfig morestatus.show=True
$ setconfig rebase.singletransaction=True
$ setconfig rebase.experimental.inmemory=True
$ setconfig rebase.experimental.inmemory.nomergedriver=False
$ setconfig rebase.experimental.inmemory.canrebaseworkingcopy=True
$ setconfig rebase.experimental.inmemory.newconflictswitching=True
$ setconfig rebase.experimental.inmemorywarning="rebasing in-memory!"
$ hg debugdrawdag <<'EOS'
> c
> |
> b g
> |/
> a
> EOS
$ hg up -q g
$ echo "conflict" > c
$ hg add -q
$ hg amend -q
$ hg up c
2 files updated, 0 files merged, 1 files removed, 0 files unresolved
$ echo "local change" > b
$ hg rebase -r tip -d . --tool :abort
rebasing in-memory!
rebasing 3:955ac081fc7c "g" (tip)
hit merge conflicts, and --tool :abort passed; exiting.
$ hg st
M b
$ cat b
local change
A rebase without a conflict behaves the same:
$ hg rebase -r tip -d .~1 --tool :abort
rebasing in-memory!
rebasing 3:955ac081fc7c "g" (tip)
saved backup bundle to $TESTTMP/repo1/.hg/strip-backup/955ac081fc7c-77e57574-rebase.hg
It fails without IMM:
$ setconfig rebase.experimental.inmemory=False
$ hg up -C .
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ hg st
$ hg rebase -r tip -d . --tool :abort
rebasing 3:20b9638feb86 "g" (tip)
transaction abort!
rollback completed
abort: --tool :abort only works with in-memory merge
[255]