3 test_description
='git rebase --onto A...B'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
10 .
"$TEST_DIRECTORY/lib-rebase.sh"
12 # Rebase only the tip commit of "topic" on merge base between "main"
13 # and "topic". Cannot do this for "side" with "main" because there
14 # is no single merge base.
19 # A---B---C---D---E main --> A---B---C---D---E
25 test_expect_success setup
'
49 test_expect_success
'rebase --onto main...topic' '
54 git rebase --onto main...topic F &&
55 git rev-parse HEAD^1 >actual &&
56 git rev-parse C^0 >expect &&
57 test_cmp expect actual
60 test_expect_success
'rebase --onto main...' '
65 git rebase --onto main... F &&
66 git rev-parse HEAD^1 >actual &&
67 git rev-parse C^0 >expect &&
68 test_cmp expect actual
71 test_expect_success
'rebase --onto main...side' '
76 test_must_fail git rebase --onto main...side J
79 test_expect_success
'rebase -i --onto main...topic' '
85 EXPECT_COUNT=1 git rebase -i --onto main...topic F
87 git rev-parse HEAD^1 >actual &&
88 git rev-parse C^0 >expect &&
89 test_cmp expect actual
92 test_expect_success
'rebase -i --onto main...' '
98 EXPECT_COUNT=1 git rebase -i --onto main... F
100 git rev-parse HEAD^1 >actual &&
101 git rev-parse C^0 >expect &&
102 test_cmp expect actual
105 test_expect_success
'rebase --onto main...side requires a single merge-base' '
108 git reset --hard K &&
110 test_must_fail git rebase -i --onto main...side J 2>err &&
111 grep "need exactly one merge base" err
114 test_expect_success
'rebase --keep-base --onto incompatible' '
115 test_must_fail git rebase --keep-base --onto main...
118 test_expect_success
'rebase --keep-base --root incompatible' '
119 test_must_fail git rebase --keep-base --root
122 test_expect_success
'rebase --keep-base main from topic' '
124 git checkout topic &&
125 git reset --hard G &&
127 git rebase --keep-base main &&
128 git rev-parse C >base.expect &&
129 git merge-base main HEAD >base.actual &&
130 test_cmp base.expect base.actual &&
132 git rev-parse HEAD~2 >actual &&
133 git rev-parse C^0 >expect &&
134 test_cmp expect actual
137 test_expect_success
'rebase --keep-base main topic from main' '
139 git branch -f topic G &&
141 git rebase --keep-base main topic &&
142 git rev-parse C >base.expect &&
143 git merge-base main HEAD >base.actual &&
144 test_cmp base.expect base.actual &&
146 git rev-parse HEAD~2 >actual &&
147 git rev-parse C^0 >expect &&
148 test_cmp expect actual
151 test_expect_success
'rebase --keep-base main from side' '
154 git reset --hard K &&
156 test_must_fail git rebase --keep-base main
159 test_expect_success
'rebase -i --keep-base main from topic' '
161 git checkout topic &&
162 git reset --hard G &&
166 EXPECT_COUNT=2 git rebase -i --keep-base main
168 git rev-parse C >base.expect &&
169 git merge-base main HEAD >base.actual &&
170 test_cmp base.expect base.actual &&
172 git rev-parse HEAD~2 >actual &&
173 git rev-parse C^0 >expect &&
174 test_cmp expect actual
177 test_expect_success
'rebase -i --keep-base main topic from main' '
179 git branch -f topic G &&
183 EXPECT_COUNT=2 git rebase -i --keep-base main topic
185 git rev-parse C >base.expect &&
186 git merge-base main HEAD >base.actual &&
187 test_cmp base.expect base.actual &&
189 git rev-parse HEAD~2 >actual &&
190 git rev-parse C^0 >expect &&
191 test_cmp expect actual
194 test_expect_success
'rebase --keep-base requires a single merge base' '
197 git reset --hard K &&
199 test_must_fail git rebase -i --keep-base main 2>err &&
200 grep "need exactly one merge base with branch" err
203 test_expect_success
'rebase --keep-base keeps cherry picks' '
204 git checkout -f -B main E &&
208 EXPECT_COUNT=2 git rebase -i --keep-base HEAD G
213 test_expect_success
'rebase --keep-base --no-reapply-cherry-picks' '
214 git checkout -f -B main E &&
218 EXPECT_COUNT=1 git rebase -i --keep-base \
219 --no-reapply-cherry-picks HEAD G
224 # This must be the last test in this file
225 test_expect_success
'$EDITOR and friends are unchanged' '
226 test_editor_unchanged