3 test_description
='git rebase --onto A...B'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 .
"$TEST_DIRECTORY/lib-rebase.sh"
11 # Rebase only the tip commit of "topic" on merge base between "main"
12 # and "topic". Cannot do this for "side" with "main" because there
13 # is no single merge base.
18 # A---B---C---D---E main --> A---B---C---D---E
24 test_expect_success setup
'
48 test_expect_success
'rebase --onto main...topic' '
53 git rebase --onto main...topic F &&
54 git rev-parse HEAD^1 >actual &&
55 git rev-parse C^0 >expect &&
56 test_cmp expect actual
59 test_expect_success
'rebase --onto main...' '
64 git rebase --onto main... F &&
65 git rev-parse HEAD^1 >actual &&
66 git rev-parse C^0 >expect &&
67 test_cmp expect actual
70 test_expect_success
'rebase --onto main...side' '
75 test_must_fail git rebase --onto main...side J
78 test_expect_success
'rebase -i --onto main...topic' '
84 EXPECT_COUNT=1 git rebase -i --onto main...topic F
86 git rev-parse HEAD^1 >actual &&
87 git rev-parse C^0 >expect &&
88 test_cmp expect actual
91 test_expect_success
'rebase -i --onto main...' '
97 EXPECT_COUNT=1 git rebase -i --onto main... F
99 git rev-parse HEAD^1 >actual &&
100 git rev-parse C^0 >expect &&
101 test_cmp expect actual
104 test_expect_success
'rebase --onto main...side requires a single merge-base' '
107 git reset --hard K &&
109 test_must_fail git rebase -i --onto main...side J 2>err &&
110 grep "need exactly one merge base" err
113 test_expect_success
'rebase --keep-base --onto incompatible' '
114 test_must_fail git rebase --keep-base --onto main...
117 test_expect_success
'rebase --keep-base --root incompatible' '
118 test_must_fail git rebase --keep-base --root
121 test_expect_success
'rebase --keep-base main from topic' '
123 git checkout topic &&
124 git reset --hard G &&
126 git rebase --keep-base main &&
127 git rev-parse C >base.expect &&
128 git merge-base main HEAD >base.actual &&
129 test_cmp base.expect base.actual &&
131 git rev-parse HEAD~2 >actual &&
132 git rev-parse C^0 >expect &&
133 test_cmp expect actual
136 test_expect_success
'rebase --keep-base main topic from main' '
138 git branch -f topic G &&
140 git rebase --keep-base main topic &&
141 git rev-parse C >base.expect &&
142 git merge-base main HEAD >base.actual &&
143 test_cmp base.expect base.actual &&
145 git rev-parse HEAD~2 >actual &&
146 git rev-parse C^0 >expect &&
147 test_cmp expect actual
150 test_expect_success
'rebase --keep-base main from side' '
153 git reset --hard K &&
155 test_must_fail git rebase --keep-base main
158 test_expect_success
'rebase -i --keep-base main from topic' '
160 git checkout topic &&
161 git reset --hard G &&
165 EXPECT_COUNT=2 git rebase -i --keep-base main
167 git rev-parse C >base.expect &&
168 git merge-base main HEAD >base.actual &&
169 test_cmp base.expect base.actual &&
171 git rev-parse HEAD~2 >actual &&
172 git rev-parse C^0 >expect &&
173 test_cmp expect actual
176 test_expect_success
'rebase -i --keep-base main topic from main' '
178 git branch -f topic G &&
182 EXPECT_COUNT=2 git rebase -i --keep-base main topic
184 git rev-parse C >base.expect &&
185 git merge-base main HEAD >base.actual &&
186 test_cmp base.expect base.actual &&
188 git rev-parse HEAD~2 >actual &&
189 git rev-parse C^0 >expect &&
190 test_cmp expect actual
193 test_expect_success
'rebase --keep-base requires a single merge base' '
196 git reset --hard K &&
198 test_must_fail git rebase -i --keep-base main 2>err &&
199 grep "need exactly one merge base with branch" err
202 test_expect_success
'rebase --keep-base keeps cherry picks' '
203 git checkout -f -B main E &&
207 EXPECT_COUNT=2 git rebase -i --keep-base HEAD G
212 test_expect_success
'rebase --keep-base --no-reapply-cherry-picks' '
213 git checkout -f -B main E &&
217 EXPECT_COUNT=1 git rebase -i --keep-base \
218 --no-reapply-cherry-picks HEAD G
223 # This must be the last test in this file
224 test_expect_success
'$EDITOR and friends are unchanged' '
225 test_editor_unchanged