]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3416-rebase-onto-threedots.sh
Sync with Git 2.45.1
[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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY/lib-rebase.sh"
11
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.
15 #
16 #
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
24
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
47 '
48
49 test_expect_success 'rebase --onto main...topic' '
50 git reset --hard &&
51 git checkout topic &&
52 git reset --hard G &&
53
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
58 '
59
60 test_expect_success 'rebase --onto main...' '
61 git reset --hard &&
62 git checkout topic &&
63 git reset --hard G &&
64
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
69 '
70
71 test_expect_success 'rebase --onto main...side' '
72 git reset --hard &&
73 git checkout side &&
74 git reset --hard K &&
75
76 test_must_fail git rebase --onto main...side J
77 '
78
79 test_expect_success 'rebase -i --onto main...topic' '
80 git reset --hard &&
81 git checkout topic &&
82 git reset --hard G &&
83 (
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
90 '
91
92 test_expect_success 'rebase -i --onto main...' '
93 git reset --hard &&
94 git checkout topic &&
95 git reset --hard G &&
96 (
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
103 '
104
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 &&
109
110 test_must_fail git rebase -i --onto main...side J 2>err &&
111 grep "need exactly one merge base" err
112 '
113
114 test_expect_success 'rebase --keep-base --onto incompatible' '
115 test_must_fail git rebase --keep-base --onto main...
116 '
117
118 test_expect_success 'rebase --keep-base --root incompatible' '
119 test_must_fail git rebase --keep-base --root
120 '
121
122 test_expect_success 'rebase --keep-base main from topic' '
123 git reset --hard &&
124 git checkout topic &&
125 git reset --hard G &&
126
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 &&
131
132 git rev-parse HEAD~2 >actual &&
133 git rev-parse C^0 >expect &&
134 test_cmp expect actual
135 '
136
137 test_expect_success 'rebase --keep-base main topic from main' '
138 git checkout main &&
139 git branch -f topic G &&
140
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 &&
145
146 git rev-parse HEAD~2 >actual &&
147 git rev-parse C^0 >expect &&
148 test_cmp expect actual
149 '
150
151 test_expect_success 'rebase --keep-base main from side' '
152 git reset --hard &&
153 git checkout side &&
154 git reset --hard K &&
155
156 test_must_fail git rebase --keep-base main
157 '
158
159 test_expect_success 'rebase -i --keep-base main from topic' '
160 git reset --hard &&
161 git checkout topic &&
162 git reset --hard G &&
163
164 (
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 &&
171
172 git rev-parse HEAD~2 >actual &&
173 git rev-parse C^0 >expect &&
174 test_cmp expect actual
175 '
176
177 test_expect_success 'rebase -i --keep-base main topic from main' '
178 git checkout main &&
179 git branch -f topic G &&
180
181 (
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 &&
188
189 git rev-parse HEAD~2 >actual &&
190 git rev-parse C^0 >expect &&
191 test_cmp expect actual
192 '
193
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 &&
198
199 test_must_fail git rebase -i --keep-base main 2>err &&
200 grep "need exactly one merge base with branch" err
201 '
202
203 test_expect_success 'rebase --keep-base keeps cherry picks' '
204 git checkout -f -B main E &&
205 git cherry-pick F &&
206 (
207 set_fake_editor &&
208 EXPECT_COUNT=2 git rebase -i --keep-base HEAD G
209 ) &&
210 test_cmp_rev HEAD G
211 '
212
213 test_expect_success 'rebase --keep-base --no-reapply-cherry-picks' '
214 git checkout -f -B main E &&
215 git cherry-pick F &&
216 (
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
222 '
223
224 # This must be the last test in this file
225 test_expect_success '$EDITOR and friends are unchanged' '
226 test_editor_unchanged
227 '
228
229 test_done