Skip to content

Commit

Permalink
rebase: validate repo state when transitioning to on-disk mode
Browse files Browse the repository at this point in the history
Summary:
In-memory rebase allows for a dirty working copy (since it doesn't use the working copy). However, when transitioning from in-memory rebase to on-disk rebase due to a conflict, we weren't validating that the working copy was clean. This lead to confusing/incorrect results when rebasing in a working copy with multiple parents. In particular, it reported the destination commit already had all the source commit's changes.

Fix by adding a `bailifchanged` when transitioning from in-memory to on-disk. I also tightened up the check around the "resuming interrupted rebase" to only ignore multiple parents in the `--continue` case.

Reviewed By: zzl0

Differential Revision: D66476017

fbshipit-source-id: d84c1dee3e513dc4309c569b3cefc4a8aad28f2c
  • Loading branch information
muirdm authored and facebook-github-bot committed Nov 26, 2024
1 parent 43e423f commit 1229b1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
4 changes: 3 additions & 1 deletion eden/scm/sapling/ext/rebase.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def __init__(self, repo, ui, templ, inmemory=False, opts=None):

self.collapsef = opts.get("collapse", False)
self.collapsemsg = cmdutil.logmessage(repo, opts)
self.contf = opts.get("continue", False)
self.date = opts.get("date", None)

e = opts.get("extrafn") # internal, used by e.g. hgsubversion
Expand Down Expand Up @@ -674,6 +675,7 @@ def _performrebasesubset(self, tr, subset, pos, prog):
_("%s (in %s); switching to on-disk merge\n")
% (kindstr, pathstr)
)
cmdutil.bailifchanged(repo)
ui.log(
"rebase",
rebase_imm_new_restart=str(True).lower(),
Expand Down Expand Up @@ -790,7 +792,7 @@ def _performrebaseone(self, rev, ctx, desc, tr, dest):
if self.collapsef:
storecollapsemsg(repo, self.collapsemsg)

if len(repo[None].parents()) == 2:
if self.contf and len(repo[None].parents()) == 2:
repo.ui.debug("resuming interrupted rebase\n")
else:
with ui.configoverride(
Expand Down
32 changes: 27 additions & 5 deletions eden/scm/tests/test-rebase-bail-merge-state.t
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#require no-eden

$ enable rebase undo
$ setconfig rebase.experimental.inmemory=true
$ newclientrepo
Expand All @@ -11,31 +13,51 @@
$ hg whereami
426bada5c67598ca65036d57d9e4b64b0c1ce7a0
112478962961147124edd43549aedd1a335e44bf
FIXME: not correct!
Rebase is in-memory - works okay and leaves us in merge state:
$ hg rebase -r $C -d $B
rebasing dc0947a82db8 "C"
note: not rebasing dc0947a82db8, its destination (rebasing onto) commit already has all its changes
$ hg whereami
426bada5c67598ca65036d57d9e4b64b0c1ce7a0
112478962961147124edd43549aedd1a335e44bf


Similar, but falling back to on-disk rebase:
Falling back to on-disk rebase:
$ newclientrepo
$ drawdag <<EOS
> B C # C/B = conflict
> |/
> A
> EOS
Start with rebase dest checked out:
$ hg go -q $B
$ hg debugsetparents $B $A
$ hg whereami
112478962961147124edd43549aedd1a335e44bf
426bada5c67598ca65036d57d9e4b64b0c1ce7a0
FIXME: not correct!
Rebase errors out after transitioning to on-disk merge:
$ hg rebase -r $C -d $B
rebasing ce63d6ee6316 "C"
merging B
hit merge conflicts (in B); switching to on-disk merge
abort: outstanding uncommitted merge
[255]
$ hg whereami
112478962961147124edd43549aedd1a335e44bf
426bada5c67598ca65036d57d9e4b64b0c1ce7a0

Start with rebase dest _not_ checked out:
$ hg go -q $A
$ hg debugsetparents $B $A
$ hg whereami
112478962961147124edd43549aedd1a335e44bf
426bada5c67598ca65036d57d9e4b64b0c1ce7a0
Rebase errors out after transitioning to on-disk merge:
$ hg rebase -r $C -d $B
rebasing ce63d6ee6316 "C"
note: not rebasing ce63d6ee6316, its destination (rebasing onto) commit already has all its changes
merging B
hit merge conflicts (in B); switching to on-disk merge
abort: outstanding uncommitted merge
[255]
$ hg whereami
112478962961147124edd43549aedd1a335e44bf
426bada5c67598ca65036d57d9e4b64b0c1ce7a0

0 comments on commit 1229b1d

Please sign in to comment.