Start the 2.46 cycle
[git/gitster.git] / t / t3416-rebase-onto-threedots.sh
blobf8c4ed78c9ef7ffd0fa970525bf3cab47842b55a
1 #!/bin/sh
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
9 . ./test-lib.sh
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.
17 # F---G topic G'
18 # / /
19 # A---B---C---D---E main --> A---B---C---D---E
20 # \ \ /
21 # \ x
22 # \ / \
23 # H---I---J---K side
25 test_expect_success setup '
26 test_commit A &&
27 test_commit B &&
28 git branch side &&
29 test_commit C &&
30 git branch topic &&
31 git checkout side &&
32 test_commit H &&
33 git checkout main &&
34 test_tick &&
35 git merge H &&
36 git tag D &&
37 test_commit E &&
38 git checkout topic &&
39 test_commit F &&
40 test_commit G &&
41 git checkout side &&
42 test_tick &&
43 git merge C &&
44 git tag I &&
45 test_commit J &&
46 test_commit K
49 test_expect_success 'rebase --onto main...topic' '
50 git reset --hard &&
51 git checkout topic &&
52 git reset --hard G &&
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...' '
61 git reset --hard &&
62 git checkout topic &&
63 git reset --hard G &&
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' '
72 git reset --hard &&
73 git checkout side &&
74 git reset --hard K &&
76 test_must_fail git rebase --onto main...side J
79 test_expect_success 'rebase -i --onto main...topic' '
80 git reset --hard &&
81 git checkout topic &&
82 git reset --hard G &&
84 set_fake_editor &&
85 EXPECT_COUNT=1 git rebase -i --onto main...topic F
86 ) &&
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...' '
93 git reset --hard &&
94 git checkout topic &&
95 git reset --hard G &&
97 set_fake_editor &&
98 EXPECT_COUNT=1 git rebase -i --onto main... F
99 ) &&
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' '
106 git reset --hard &&
107 git checkout side &&
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' '
123 git reset --hard &&
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' '
138 git checkout 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' '
152 git reset --hard &&
153 git checkout 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' '
160 git reset --hard &&
161 git checkout topic &&
162 git reset --hard G &&
165 set_fake_editor &&
166 EXPECT_COUNT=2 git rebase -i --keep-base main
167 ) &&
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' '
178 git checkout main &&
179 git branch -f topic G &&
182 set_fake_editor &&
183 EXPECT_COUNT=2 git rebase -i --keep-base main topic
184 ) &&
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' '
195 git reset --hard &&
196 git checkout side &&
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 &&
205 git cherry-pick F &&
207 set_fake_editor &&
208 EXPECT_COUNT=2 git rebase -i --keep-base HEAD G
209 ) &&
210 test_cmp_rev HEAD G
213 test_expect_success 'rebase --keep-base --no-reapply-cherry-picks' '
214 git checkout -f -B main E &&
215 git cherry-pick F &&
217 set_fake_editor &&
218 EXPECT_COUNT=1 git rebase -i --keep-base \
219 --no-reapply-cherry-picks HEAD G
220 ) &&
221 test_cmp_rev HEAD^ C
224 # This must be the last test in this file
225 test_expect_success '$EDITOR and friends are unchanged' '
226 test_editor_unchanged
229 test_done