# HG changeset patch # User Sune Foldager # Date 2009-10-08 08:39:43 # Node ID 341182ac95e44bc2b2ec249665aba41ccf76df67 # Parent b91960aed018b7fbcc9648ec6e823a9b7626f0da rebase: return early when source is descendant of destination This only happens when using --base (or no source selection options), as rebase already aborts in this situation when using --source. Without this change you get an abort from the underlying merge, and the repository is in a different state than you started with (the working dir parent is changed). diff --git a/hgext/rebase.py b/hgext/rebase.py --- a/hgext/rebase.py +++ b/hgext/rebase.py @@ -401,6 +401,10 @@ def buildstate(repo, dest, src, base, co return None cwdancestors = set(repo.changelog.ancestors(cwd)) + if dest in cwdancestors: + repo.ui.debug('source is descendant of destination\n') + return None + cwdancestors.add(cwd) rebasingbranch = cwdancestors - targetancestors source = min(rebasingbranch) diff --git a/tests/test-rebase-scenario-global b/tests/test-rebase-scenario-global --- a/tests/test-rebase-scenario-global +++ b/tests/test-rebase-scenario-global @@ -70,7 +70,7 @@ echo '% D onto B - E maintains C as pare hg rebase -s 3 -d 1 2>&1 | sed 's/\(saving bundle to \).*/\1/' hg glog --template '{rev}: {desc}\n' -echo '% These will fail' +echo '% These will fail (using --source)' createrepo > /dev/null 2>&1 echo '% E onto D - rebase onto an ancestor' hg rebase -s 4 -d 3 @@ -79,4 +79,13 @@ hg rebase -s 3 -d 4 echo '% E onto B - merge revision with both parents not in ancestors of target' hg rebase -s 4 -d 1 +echo +echo '% These will abort gracefully (using --base)' +echo '% E onto E - rebase onto same changeset' +hg rebase -b 4 -d 4 +echo '% E onto D - rebase onto an ancestor' +hg rebase -b 4 -d 3 +echo '% D onto E - rebase onto a descendant' +hg rebase -b 3 -d 4 + exit 0 diff --git a/tests/test-rebase-scenario-global.out b/tests/test-rebase-scenario-global.out --- a/tests/test-rebase-scenario-global.out +++ b/tests/test-rebase-scenario-global.out @@ -127,10 +127,18 @@ o | 1: B |/ o 0: A -% These will fail +% These will fail (using --source) % E onto D - rebase onto an ancestor abort: source is descendant of destination % D onto E - rebase onto a descendant abort: source is ancestor of destination % E onto B - merge revision with both parents not in ancestors of target abort: cannot use revision 4 as base, result would have 3 parents + +% These will abort gracefully (using --base) +% E onto E - rebase onto same changeset +nothing to rebase +% E onto D - rebase onto an ancestor +nothing to rebase +% D onto E - rebase onto a descendant +nothing to rebase