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