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