]>
Commit | Line | Data |
---|---|---|
190f5323 TR |
1 | #!/bin/sh |
2 | ||
3 | test_description='git rebase --root | |
4 | ||
5 | Tests if git rebase --root --onto <newparent> can rebase the root commit. | |
6 | ' | |
7 | . ./test-lib.sh | |
21828964 | 8 | |
2ea3c171 TR |
9 | log_with_names () { |
10 | git rev-list --topo-order --parents --pretty="tformat:%s" HEAD | | |
11 | git name-rev --stdin --name-only --refs=refs/heads/$1 | |
12 | } | |
13 | ||
14 | ||
190f5323 | 15 | test_expect_success 'prepare repository' ' |
f7951e1d JS |
16 | test_commit 1 A && |
17 | test_commit 2 A && | |
190f5323 TR |
18 | git symbolic-ref HEAD refs/heads/other && |
19 | rm .git/index && | |
f7951e1d JS |
20 | test_commit 3 B && |
21 | test_commit 1b A 1 && | |
22 | test_commit 4 B | |
190f5323 TR |
23 | ' |
24 | ||
25 | test_expect_success 'rebase --root expects --onto' ' | |
26 | test_must_fail git rebase --root | |
27 | ' | |
28 | ||
29 | test_expect_success 'setup pre-rebase hook' ' | |
30 | mkdir -p .git/hooks && | |
31 | cat >.git/hooks/pre-rebase <<EOF && | |
32 | #!$SHELL_PATH | |
33 | echo "\$1,\$2" >.git/PRE-REBASE-INPUT | |
34 | EOF | |
35 | chmod +x .git/hooks/pre-rebase | |
36 | ' | |
37 | cat > expect <<EOF | |
38 | 4 | |
39 | 3 | |
40 | 2 | |
41 | 1 | |
42 | EOF | |
43 | ||
44 | test_expect_success 'rebase --root --onto <newbase>' ' | |
45 | git checkout -b work && | |
46 | git rebase --root --onto master && | |
47 | git log --pretty=tformat:"%s" > rebased && | |
48 | test_cmp expect rebased | |
49 | ' | |
50 | ||
51 | test_expect_success 'pre-rebase got correct input (1)' ' | |
52 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root, | |
53 | ' | |
54 | ||
55 | test_expect_success 'rebase --root --onto <newbase> <branch>' ' | |
56 | git branch work2 other && | |
57 | git rebase --root --onto master work2 && | |
58 | git log --pretty=tformat:"%s" > rebased2 && | |
59 | test_cmp expect rebased2 | |
60 | ' | |
61 | ||
62 | test_expect_success 'pre-rebase got correct input (2)' ' | |
63 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2 | |
64 | ' | |
65 | ||
d911d146 TR |
66 | test_expect_success 'rebase -i --root --onto <newbase>' ' |
67 | git checkout -b work3 other && | |
21828964 | 68 | git rebase -i --root --onto master && |
d911d146 TR |
69 | git log --pretty=tformat:"%s" > rebased3 && |
70 | test_cmp expect rebased3 | |
71 | ' | |
72 | ||
73 | test_expect_success 'pre-rebase got correct input (3)' ' | |
74 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root, | |
75 | ' | |
76 | ||
77 | test_expect_success 'rebase -i --root --onto <newbase> <branch>' ' | |
78 | git branch work4 other && | |
21828964 | 79 | git rebase -i --root --onto master work4 && |
d911d146 TR |
80 | git log --pretty=tformat:"%s" > rebased4 && |
81 | test_cmp expect rebased4 | |
82 | ' | |
83 | ||
84 | test_expect_success 'pre-rebase got correct input (4)' ' | |
85 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4 | |
86 | ' | |
87 | ||
88 | test_expect_success 'rebase -i -p with linear history' ' | |
89 | git checkout -b work5 other && | |
21828964 | 90 | git rebase -i -p --root --onto master && |
d911d146 TR |
91 | git log --pretty=tformat:"%s" > rebased5 && |
92 | test_cmp expect rebased5 | |
93 | ' | |
94 | ||
95 | test_expect_success 'pre-rebase got correct input (5)' ' | |
96 | test "z$(cat .git/PRE-REBASE-INPUT)" = z--root, | |
97 | ' | |
98 | ||
99 | test_expect_success 'set up merge history' ' | |
100 | git checkout other^ && | |
101 | git checkout -b side && | |
f7951e1d | 102 | test_commit 5 C && |
d911d146 TR |
103 | git checkout other && |
104 | git merge side | |
105 | ' | |
106 | ||
2ea3c171 TR |
107 | cat > expect-side <<'EOF' |
108 | commit work6 work6~1 work6^2 | |
109 | Merge branch 'side' into other | |
110 | commit work6^2 work6~2 | |
111 | 5 | |
112 | commit work6~1 work6~2 | |
113 | 4 | |
114 | commit work6~2 work6~3 | |
115 | 3 | |
116 | commit work6~3 work6~4 | |
117 | 2 | |
118 | commit work6~4 | |
119 | 1 | |
d911d146 TR |
120 | EOF |
121 | ||
122 | test_expect_success 'rebase -i -p with merge' ' | |
123 | git checkout -b work6 other && | |
21828964 | 124 | git rebase -i -p --root --onto master && |
2ea3c171 | 125 | log_with_names work6 > rebased6 && |
d911d146 TR |
126 | test_cmp expect-side rebased6 |
127 | ' | |
128 | ||
129 | test_expect_success 'set up second root and merge' ' | |
130 | git symbolic-ref HEAD refs/heads/third && | |
131 | rm .git/index && | |
132 | rm A B C && | |
f7951e1d | 133 | test_commit 6 D && |
d911d146 TR |
134 | git checkout other && |
135 | git merge third | |
136 | ' | |
137 | ||
2ea3c171 TR |
138 | cat > expect-third <<'EOF' |
139 | commit work7 work7~1 work7^2 | |
140 | Merge branch 'third' into other | |
141 | commit work7^2 work7~4 | |
142 | 6 | |
143 | commit work7~1 work7~2 work7~1^2 | |
144 | Merge branch 'side' into other | |
145 | commit work7~1^2 work7~3 | |
146 | 5 | |
147 | commit work7~2 work7~3 | |
148 | 4 | |
149 | commit work7~3 work7~4 | |
150 | 3 | |
151 | commit work7~4 work7~5 | |
152 | 2 | |
153 | commit work7~5 | |
154 | 1 | |
d911d146 TR |
155 | EOF |
156 | ||
157 | test_expect_success 'rebase -i -p with two roots' ' | |
158 | git checkout -b work7 other && | |
21828964 | 159 | git rebase -i -p --root --onto master && |
2ea3c171 | 160 | log_with_names work7 > rebased7 && |
d911d146 TR |
161 | test_cmp expect-third rebased7 |
162 | ' | |
163 | ||
190f5323 TR |
164 | test_expect_success 'setup pre-rebase hook that fails' ' |
165 | mkdir -p .git/hooks && | |
166 | cat >.git/hooks/pre-rebase <<EOF && | |
167 | #!$SHELL_PATH | |
168 | false | |
169 | EOF | |
170 | chmod +x .git/hooks/pre-rebase | |
171 | ' | |
172 | ||
173 | test_expect_success 'pre-rebase hook stops rebase' ' | |
174 | git checkout -b stops1 other && | |
21828964 | 175 | test_must_fail git rebase --root --onto master && |
a48fcd83 | 176 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 && |
190f5323 TR |
177 | test 0 = $(git rev-list other...stops1 | wc -l) |
178 | ' | |
179 | ||
d911d146 TR |
180 | test_expect_success 'pre-rebase hook stops rebase -i' ' |
181 | git checkout -b stops2 other && | |
21828964 | 182 | test_must_fail git rebase --root --onto master && |
a48fcd83 | 183 | test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 && |
d911d146 TR |
184 | test 0 = $(git rev-list other...stops2 | wc -l) |
185 | ' | |
186 | ||
a6c7a276 JH |
187 | test_expect_success 'remove pre-rebase hook' ' |
188 | rm -f .git/hooks/pre-rebase | |
189 | ' | |
190 | ||
191 | test_expect_success 'set up a conflict' ' | |
192 | git checkout master && | |
193 | echo conflict > B && | |
194 | git add B && | |
195 | git commit -m conflict | |
196 | ' | |
197 | ||
198 | test_expect_success 'rebase --root with conflict (first part)' ' | |
199 | git checkout -b conflict1 other && | |
200 | test_must_fail git rebase --root --onto master && | |
201 | git ls-files -u | grep "B$" | |
202 | ' | |
203 | ||
204 | test_expect_success 'fix the conflict' ' | |
205 | echo 3 > B && | |
206 | git add B | |
207 | ' | |
208 | ||
209 | cat > expect-conflict <<EOF | |
210 | 6 | |
211 | 5 | |
212 | 4 | |
213 | 3 | |
214 | conflict | |
215 | 2 | |
216 | 1 | |
217 | EOF | |
218 | ||
219 | test_expect_success 'rebase --root with conflict (second part)' ' | |
220 | git rebase --continue && | |
221 | git log --pretty=tformat:"%s" > conflict1 && | |
222 | test_cmp expect-conflict conflict1 | |
223 | ' | |
224 | ||
225 | test_expect_success 'rebase -i --root with conflict (first part)' ' | |
226 | git checkout -b conflict2 other && | |
21828964 | 227 | test_must_fail git rebase -i --root --onto master && |
a6c7a276 JH |
228 | git ls-files -u | grep "B$" |
229 | ' | |
230 | ||
231 | test_expect_success 'fix the conflict' ' | |
232 | echo 3 > B && | |
233 | git add B | |
234 | ' | |
235 | ||
236 | test_expect_success 'rebase -i --root with conflict (second part)' ' | |
237 | git rebase --continue && | |
238 | git log --pretty=tformat:"%s" > conflict2 && | |
239 | test_cmp expect-conflict conflict2 | |
240 | ' | |
241 | ||
242 | cat >expect-conflict-p <<\EOF | |
243 | commit conflict3 conflict3~1 conflict3^2 | |
244 | Merge branch 'third' into other | |
245 | commit conflict3^2 conflict3~4 | |
246 | 6 | |
247 | commit conflict3~1 conflict3~2 conflict3~1^2 | |
248 | Merge branch 'side' into other | |
249 | commit conflict3~1^2 conflict3~3 | |
250 | 5 | |
251 | commit conflict3~2 conflict3~3 | |
252 | 4 | |
253 | commit conflict3~3 conflict3~4 | |
254 | 3 | |
255 | commit conflict3~4 conflict3~5 | |
256 | conflict | |
257 | commit conflict3~5 conflict3~6 | |
258 | 2 | |
259 | commit conflict3~6 | |
260 | 1 | |
261 | EOF | |
262 | ||
263 | test_expect_success 'rebase -i -p --root with conflict (first part)' ' | |
264 | git checkout -b conflict3 other && | |
21828964 | 265 | test_must_fail git rebase -i -p --root --onto master && |
a6c7a276 JH |
266 | git ls-files -u | grep "B$" |
267 | ' | |
268 | ||
269 | test_expect_success 'fix the conflict' ' | |
270 | echo 3 > B && | |
271 | git add B | |
272 | ' | |
273 | ||
274 | test_expect_success 'rebase -i -p --root with conflict (second part)' ' | |
275 | git rebase --continue && | |
2ea3c171 | 276 | log_with_names conflict3 >out && |
a6c7a276 JH |
277 | test_cmp expect-conflict-p out |
278 | ' | |
279 | ||
190f5323 | 280 | test_done |