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