]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3412-rebase-root.sh
Add tests for rebase -i --root without --onto
[thirdparty/git.git] / t / t3412-rebase-root.sh
CommitLineData
190f5323
TR
1#!/bin/sh
2
3test_description='git rebase --root
4
5Tests if git rebase --root --onto <newparent> can rebase the root commit.
6'
7. ./test-lib.sh
21828964 8
2ea3c171
TR
9log_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 15test_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
25test_expect_success 'setup pre-rebase hook' '
26 mkdir -p .git/hooks &&
27 cat >.git/hooks/pre-rebase <<EOF &&
28#!$SHELL_PATH
29echo "\$1,\$2" >.git/PRE-REBASE-INPUT
30EOF
31 chmod +x .git/hooks/pre-rebase
32'
33cat > expect <<EOF
344
353
362
371
38EOF
39
40test_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
47test_expect_success 'pre-rebase got correct input (1)' '
48 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
49'
50
51test_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
58test_expect_success 'pre-rebase got correct input (2)' '
59 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
60'
61
d911d146
TR
62test_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
69test_expect_success 'pre-rebase got correct input (3)' '
70 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
71'
72
73test_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
80test_expect_success 'pre-rebase got correct input (4)' '
81 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
82'
83
84test_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
91test_expect_success 'pre-rebase got correct input (5)' '
92 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
93'
94
95test_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
103cat > expect-side <<'EOF'
104commit work6 work6~1 work6^2
105Merge branch 'side' into other
106commit work6^2 work6~2
1075
108commit work6~1 work6~2
1094
110commit work6~2 work6~3
1113
112commit work6~3 work6~4
1132
114commit work6~4
1151
d911d146
TR
116EOF
117
118test_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
125test_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
134cat > expect-third <<'EOF'
135commit work7 work7~1 work7^2
136Merge branch 'third' into other
137commit work7^2 work7~4
1386
139commit work7~1 work7~2 work7~1^2
140Merge branch 'side' into other
141commit work7~1^2 work7~3
1425
143commit work7~2 work7~3
1444
145commit work7~3 work7~4
1463
147commit work7~4 work7~5
1482
149commit work7~5
1501
d911d146
TR
151EOF
152
153test_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
160test_expect_success 'setup pre-rebase hook that fails' '
161 mkdir -p .git/hooks &&
162 cat >.git/hooks/pre-rebase <<EOF &&
163#!$SHELL_PATH
164false
165EOF
166 chmod +x .git/hooks/pre-rebase
167'
168
169test_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
176test_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
183test_expect_success 'remove pre-rebase hook' '
184 rm -f .git/hooks/pre-rebase
185'
186
187test_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
194test_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
200test_expect_success 'fix the conflict' '
201 echo 3 > B &&
202 git add B
203'
204
205cat > expect-conflict <<EOF
2066
2075
2084
2093
210conflict
2112
2121
213EOF
214
215test_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
221test_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
227test_expect_success 'fix the conflict' '
228 echo 3 > B &&
229 git add B
230'
231
232test_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
238cat >expect-conflict-p <<\EOF
239commit conflict3 conflict3~1 conflict3^2
240Merge branch 'third' into other
241commit conflict3^2 conflict3~4
2426
243commit conflict3~1 conflict3~2 conflict3~1^2
244Merge branch 'side' into other
245commit conflict3~1^2 conflict3~3
2465
247commit conflict3~2 conflict3~3
2484
249commit conflict3~3 conflict3~4
2503
251commit conflict3~4 conflict3~5
252conflict
253commit conflict3~5 conflict3~6
2542
255commit conflict3~6
2561
257EOF
258
259test_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
265test_expect_success 'fix the conflict' '
266 echo 3 > B &&
267 git add B
268'
269
270test_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 276test_done