]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3412-rebase-root.sh
tests: use "test_hook" for misc "mkdir -p" and "chmod" cases
[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'
d1c02d93 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
190f5323 10. ./test-lib.sh
21828964 11
2ea3c171
TR
12log_with_names () {
13 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
34ae3b70 14 git name-rev --annotate-stdin --name-only --refs=refs/heads/$1
2ea3c171
TR
15}
16
17
190f5323 18test_expect_success 'prepare repository' '
f7951e1d
JS
19 test_commit 1 A &&
20 test_commit 2 A &&
190f5323
TR
21 git symbolic-ref HEAD refs/heads/other &&
22 rm .git/index &&
f7951e1d
JS
23 test_commit 3 B &&
24 test_commit 1b A 1 &&
25 test_commit 4 B
190f5323
TR
26'
27
f2b6a199
MZ
28test_expect_success 'rebase --root fails with too many args' '
29 git checkout -B fail other &&
d1c02d93 30 test_must_fail git rebase --onto main --root fail fail
f2b6a199
MZ
31'
32
190f5323 33test_expect_success 'setup pre-rebase hook' '
c36c6285
ÆAB
34 test_hook --setup pre-rebase <<-\EOF
35 echo "$1,$2" >.git/PRE-REBASE-INPUT
36 EOF
190f5323
TR
37'
38cat > expect <<EOF
394
403
412
421
43EOF
44
45test_expect_success 'rebase --root --onto <newbase>' '
f2b6a199 46 git checkout -b work other &&
d1c02d93 47 git rebase --root --onto main &&
190f5323
TR
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 &&
d1c02d93 58 git rebase --root --onto main work2 &&
190f5323
TR
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 &&
d1c02d93 69 git rebase -i --root --onto main &&
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 &&
d1c02d93 80 git rebase -i --root --onto main 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
d911d146
TR
89test_expect_success 'set up merge history' '
90 git checkout other^ &&
91 git checkout -b side &&
f7951e1d 92 test_commit 5 C &&
d911d146
TR
93 git checkout other &&
94 git merge side
95'
96
2ea3c171
TR
97cat > expect-side <<'EOF'
98commit work6 work6~1 work6^2
99Merge branch 'side' into other
100commit work6^2 work6~2
1015
102commit work6~1 work6~2
1034
104commit work6~2 work6~3
1053
106commit work6~3 work6~4
1072
108commit work6~4
1091
d911d146
TR
110EOF
111
d911d146
TR
112test_expect_success 'set up second root and merge' '
113 git symbolic-ref HEAD refs/heads/third &&
114 rm .git/index &&
115 rm A B C &&
f7951e1d 116 test_commit 6 D &&
d911d146 117 git checkout other &&
e379fdf3 118 git merge --allow-unrelated-histories third
d911d146
TR
119'
120
2ea3c171
TR
121cat > expect-third <<'EOF'
122commit work7 work7~1 work7^2
123Merge branch 'third' into other
124commit work7^2 work7~4
1256
126commit work7~1 work7~2 work7~1^2
127Merge branch 'side' into other
128commit work7~1^2 work7~3
1295
130commit work7~2 work7~3
1314
132commit work7~3 work7~4
1333
134commit work7~4 work7~5
1352
136commit work7~5
1371
d911d146
TR
138EOF
139
190f5323 140test_expect_success 'setup pre-rebase hook that fails' '
c36c6285
ÆAB
141 test_hook --setup --clobber pre-rebase <<-\EOF
142 false
143 EOF
190f5323
TR
144'
145
146test_expect_success 'pre-rebase hook stops rebase' '
147 git checkout -b stops1 other &&
d1c02d93 148 test_must_fail git rebase --root --onto main &&
a48fcd83 149 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
190f5323
TR
150 test 0 = $(git rev-list other...stops1 | wc -l)
151'
152
d911d146
TR
153test_expect_success 'pre-rebase hook stops rebase -i' '
154 git checkout -b stops2 other &&
d1c02d93 155 test_must_fail git rebase --root --onto main &&
a48fcd83 156 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
d911d146
TR
157 test 0 = $(git rev-list other...stops2 | wc -l)
158'
159
a6c7a276
JH
160test_expect_success 'remove pre-rebase hook' '
161 rm -f .git/hooks/pre-rebase
162'
163
164test_expect_success 'set up a conflict' '
d1c02d93 165 git checkout main &&
a6c7a276
JH
166 echo conflict > B &&
167 git add B &&
168 git commit -m conflict
169'
170
171test_expect_success 'rebase --root with conflict (first part)' '
172 git checkout -b conflict1 other &&
d1c02d93 173 test_must_fail git rebase --root --onto main &&
a6c7a276
JH
174 git ls-files -u | grep "B$"
175'
176
177test_expect_success 'fix the conflict' '
178 echo 3 > B &&
179 git add B
180'
181
182cat > expect-conflict <<EOF
1836
1845
1854
1863
187conflict
1882
1891
190EOF
191
192test_expect_success 'rebase --root with conflict (second part)' '
193 git rebase --continue &&
194 git log --pretty=tformat:"%s" > conflict1 &&
195 test_cmp expect-conflict conflict1
196'
197
198test_expect_success 'rebase -i --root with conflict (first part)' '
199 git checkout -b conflict2 other &&
d1c02d93 200 test_must_fail git rebase -i --root --onto main &&
a6c7a276
JH
201 git ls-files -u | grep "B$"
202'
203
204test_expect_success 'fix the conflict' '
205 echo 3 > B &&
206 git add B
207'
208
209test_expect_success 'rebase -i --root with conflict (second part)' '
210 git rebase --continue &&
211 git log --pretty=tformat:"%s" > conflict2 &&
212 test_cmp expect-conflict conflict2
213'
214
215cat >expect-conflict-p <<\EOF
216commit conflict3 conflict3~1 conflict3^2
217Merge branch 'third' into other
218commit conflict3^2 conflict3~4
2196
220commit conflict3~1 conflict3~2 conflict3~1^2
221Merge branch 'side' into other
222commit conflict3~1^2 conflict3~3
2235
224commit conflict3~2 conflict3~3
2254
226commit conflict3~3 conflict3~4
2273
228commit conflict3~4 conflict3~5
229conflict
230commit conflict3~5 conflict3~6
2312
232commit conflict3~6
2331
234EOF
235
a6c7a276
JH
236test_expect_success 'fix the conflict' '
237 echo 3 > B &&
238 git add B
239'
240
190f5323 241test_done