Skip to content

Commit d1926f6

Browse files
committed
Merge branch 'gp/maint-rebase-p-onto'
* gp/maint-rebase-p-onto: Fix rebase -p --onto
2 parents feab68c + 1830d9c commit d1926f6

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

git-rebase--interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ first and then run 'git rebase --continue' again."
703703
preserve=t
704704
for p in $(git rev-list --parents -1 $sha1 | cut -d' ' -s -f2-)
705705
do
706-
if test -f "$REWRITTEN"/$p -a \( $p != $UPSTREAM -o $sha1 = $first_after_upstream \)
706+
if test -f "$REWRITTEN"/$p -a \( $p != $ONTO -o $sha1 = $first_after_upstream \)
707707
then
708708
preserve=f
709709
fi

t/t3414-rebase-preserve-onto.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2009 Greg Price
4+
#
5+
6+
test_description='git rebase -p should respect --onto
7+
8+
In a rebase with --onto, we should rewrite all the commits that
9+
aren'"'"'t on top of $ONTO, even if they are on top of $UPSTREAM.
10+
'
11+
. ./test-lib.sh
12+
13+
. ../lib-rebase.sh
14+
15+
# Set up branches like this:
16+
# A1---B1---E1---F1---G1
17+
# \ \ /
18+
# \ \--C1---D1--/
19+
# H1
20+
21+
test_expect_success 'setup' '
22+
test_commit A1 &&
23+
test_commit B1 &&
24+
test_commit C1 &&
25+
test_commit D1 &&
26+
git reset --hard B1 &&
27+
test_commit E1 &&
28+
test_commit F1 &&
29+
test_merge G1 D1 &&
30+
git reset --hard A1 &&
31+
test_commit H1
32+
'
33+
34+
# Now rebase merge G1 from both branches' base B1, both should move:
35+
# A1---B1---E1---F1---G1
36+
# \ \ /
37+
# \ \--C1---D1--/
38+
# \
39+
# H1---E2---F2---G2
40+
# \ /
41+
# \--C2---D2--/
42+
43+
test_expect_success 'rebase from B1 onto H1' '
44+
git checkout G1 &&
45+
git rebase -p --onto H1 B1 &&
46+
test "$(git rev-parse HEAD^1^1^1)" = "$(git rev-parse H1)" &&
47+
test "$(git rev-parse HEAD^2^1^1)" = "$(git rev-parse H1)"
48+
'
49+
50+
# On the other hand if rebase from E1 which is within one branch,
51+
# then the other branch stays:
52+
# A1---B1---E1---F1---G1
53+
# \ \ /
54+
# \ \--C1---D1--/
55+
# \ \
56+
# H1-----F3-----G3
57+
58+
test_expect_success 'rebase from E1 onto H1' '
59+
git checkout G1 &&
60+
git rebase -p --onto H1 E1 &&
61+
test "$(git rev-parse HEAD^1^1)" = "$(git rev-parse H1)" &&
62+
test "$(git rev-parse HEAD^2)" = "$(git rev-parse D1)"
63+
'
64+
65+
# And the same if we rebase from a commit in the second-parent branch.
66+
# A1---B1---E1---F1----G1
67+
# \ \ \ /
68+
# \ \--C1---D1-\-/
69+
# \ \
70+
# H1------D3------G4
71+
72+
test_expect_success 'rebase from C1 onto H1' '
73+
git checkout G1 &&
74+
git rev-list --first-parent --pretty=oneline C1..G1 &&
75+
git rebase -p --onto H1 C1 &&
76+
test "$(git rev-parse HEAD^2^1)" = "$(git rev-parse H1)" &&
77+
test "$(git rev-parse HEAD^1)" = "$(git rev-parse F1)"
78+
'
79+
80+
test_done

0 commit comments

Comments
 (0)