mirror of
https://github.com/facebook/sapling.git
synced 2025-01-06 04:43:19 +03:00
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:
parent
72c3d8afc1
commit
6c605e4a52
@ -1022,6 +1022,12 @@ def rebase(ui, repo, templ=None, **opts):
|
|||||||
)
|
)
|
||||||
rbsrt.inmemory = False
|
rbsrt.inmemory = False
|
||||||
return _origrebase(ui, repo, rbsrt, **opts)
|
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:
|
else:
|
||||||
return _origrebase(ui, repo, rbsrt, **opts)
|
return _origrebase(ui, repo, rbsrt, **opts)
|
||||||
|
|
||||||
|
@ -409,3 +409,7 @@ class InMemoryMergeConflictsError(Exception):
|
|||||||
"""Exception raised when merge conflicts arose during an in-memory merge."""
|
"""Exception raised when merge conflicts arose during an in-memory merge."""
|
||||||
|
|
||||||
__bytes__ = _tobytes
|
__bytes__ = _tobytes
|
||||||
|
|
||||||
|
|
||||||
|
class AbortMergeToolError(Abort):
|
||||||
|
"""User specified :abort and there was a merge conflict; abort the merge."""
|
||||||
|
@ -247,6 +247,18 @@ def _matcheol(file, back):
|
|||||||
util.writefile(file, newdata)
|
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)
|
@internaltool("prompt", nomerge)
|
||||||
def _iprompt(repo, mynode, orig, fcd, fco, fca, toolconf, labels=None):
|
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
|
"""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.
|
# conflicts.
|
||||||
if fcd.changectx().isinmemory():
|
if fcd.changectx().isinmemory():
|
||||||
raise error.InMemoryMergeConflictsError(
|
raise error.InMemoryMergeConflictsError(
|
||||||
"in-memory merge does not " "support file conflicts"
|
"in-memory merge does not support file conflicts"
|
||||||
)
|
)
|
||||||
|
|
||||||
prompts = partextras(labels)
|
prompts = partextras(labels)
|
||||||
|
53
tests/test-rebase-inmemory-abort-tool.t
Normal file
53
tests/test-rebase-inmemory-abort-tool.t
Normal 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]
|
Loading…
Reference in New Issue
Block a user