]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3416-rebase-onto-threedots.sh
Sync with 2.38.3
[thirdparty/git.git] / t / t3416-rebase-onto-threedots.sh
1 #!/bin/sh
2
3 test_description='git rebase --onto A...B'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY/lib-rebase.sh"
10
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.
14 #
15 #
16 # F---G topic G'
17 # / /
18 # A---B---C---D---E main --> A---B---C---D---E
19 # \ \ /
20 # \ x
21 # \ / \
22 # H---I---J---K side
23
24 test_expect_success setup '
25 test_commit A &&
26 test_commit B &&
27 git branch side &&
28 test_commit C &&
29 git branch topic &&
30 git checkout side &&
31 test_commit H &&
32 git checkout main &&
33 test_tick &&
34 git merge H &&
35 git tag D &&
36 test_commit E &&
37 git checkout topic &&
38 test_commit F &&
39 test_commit G &&
40 git checkout side &&
41 test_tick &&
42 git merge C &&
43 git tag I &&
44 test_commit J &&
45 test_commit K
46 '
47
48 test_expect_success 'rebase --onto main...topic' '
49 git reset --hard &&
50 git checkout topic &&
51 git reset --hard G &&
52
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
57 '
58
59 test_expect_success 'rebase --onto main...' '
60 git reset --hard &&
61 git checkout topic &&
62 git reset --hard G &&
63
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
68 '
69
70 test_expect_success 'rebase --onto main...side' '
71 git reset --hard &&
72 git checkout side &&
73 git reset --hard K &&
74
75 test_must_fail git rebase --onto main...side J
76 '
77
78 test_expect_success 'rebase -i --onto main...topic' '
79 git reset --hard &&
80 git checkout topic &&
81 git reset --hard G &&
82 (
83 set_fake_editor &&
84 EXPECT_COUNT=1 git rebase -i --onto main...topic F
85 ) &&
86 git rev-parse HEAD^1 >actual &&
87 git rev-parse C^0 >expect &&
88 test_cmp expect actual
89 '
90
91 test_expect_success 'rebase -i --onto main...' '
92 git reset --hard &&
93 git checkout topic &&
94 git reset --hard G &&
95 (
96 set_fake_editor &&
97 EXPECT_COUNT=1 git rebase -i --onto main... F
98 ) &&
99 git rev-parse HEAD^1 >actual &&
100 git rev-parse C^0 >expect &&
101 test_cmp expect actual
102 '
103
104 test_expect_success 'rebase --onto main...side requires a single merge-base' '
105 git reset --hard &&
106 git checkout side &&
107 git reset --hard K &&
108
109 test_must_fail git rebase -i --onto main...side J 2>err &&
110 grep "need exactly one merge base" err
111 '
112
113 test_expect_success 'rebase --keep-base --onto incompatible' '
114 test_must_fail git rebase --keep-base --onto main...
115 '
116
117 test_expect_success 'rebase --keep-base --root incompatible' '
118 test_must_fail git rebase --keep-base --root
119 '
120
121 test_expect_success 'rebase --keep-base main from topic' '
122 git reset --hard &&
123 git checkout topic &&
124 git reset --hard G &&
125
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 &&
130
131 git rev-parse HEAD~2 >actual &&
132 git rev-parse C^0 >expect &&
133 test_cmp expect actual
134 '
135
136 test_expect_success 'rebase --keep-base main topic from main' '
137 git checkout main &&
138 git branch -f topic G &&
139
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 &&
144
145 git rev-parse HEAD~2 >actual &&
146 git rev-parse C^0 >expect &&
147 test_cmp expect actual
148 '
149
150 test_expect_success 'rebase --keep-base main from side' '
151 git reset --hard &&
152 git checkout side &&
153 git reset --hard K &&
154
155 test_must_fail git rebase --keep-base main
156 '
157
158 test_expect_success 'rebase -i --keep-base main from topic' '
159 git reset --hard &&
160 git checkout topic &&
161 git reset --hard G &&
162
163 (
164 set_fake_editor &&
165 EXPECT_COUNT=2 git rebase -i --keep-base main
166 ) &&
167 git rev-parse C >base.expect &&
168 git merge-base main HEAD >base.actual &&
169 test_cmp base.expect base.actual &&
170
171 git rev-parse HEAD~2 >actual &&
172 git rev-parse C^0 >expect &&
173 test_cmp expect actual
174 '
175
176 test_expect_success 'rebase -i --keep-base main topic from main' '
177 git checkout main &&
178 git branch -f topic G &&
179
180 (
181 set_fake_editor &&
182 EXPECT_COUNT=2 git rebase -i --keep-base main topic
183 ) &&
184 git rev-parse C >base.expect &&
185 git merge-base main HEAD >base.actual &&
186 test_cmp base.expect base.actual &&
187
188 git rev-parse HEAD~2 >actual &&
189 git rev-parse C^0 >expect &&
190 test_cmp expect actual
191 '
192
193 test_expect_success 'rebase --keep-base requires a single merge base' '
194 git reset --hard &&
195 git checkout side &&
196 git reset --hard K &&
197
198 test_must_fail git rebase -i --keep-base main 2>err &&
199 grep "need exactly one merge base with branch" err
200 '
201
202 test_expect_success 'rebase --keep-base keeps cherry picks' '
203 git checkout -f -B main E &&
204 git cherry-pick F &&
205 (
206 set_fake_editor &&
207 EXPECT_COUNT=2 git rebase -i --keep-base HEAD G
208 ) &&
209 test_cmp_rev HEAD G
210 '
211
212 test_expect_success 'rebase --keep-base --no-reapply-cherry-picks' '
213 git checkout -f -B main E &&
214 git cherry-pick F &&
215 (
216 set_fake_editor &&
217 EXPECT_COUNT=1 git rebase -i --keep-base \
218 --no-reapply-cherry-picks HEAD G
219 ) &&
220 test_cmp_rev HEAD^ C
221 '
222
223 # This must be the last test in this file
224 test_expect_success '$EDITOR and friends are unchanged' '
225 test_editor_unchanged
226 '
227
228 test_done