]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3412-rebase-root.sh
The third batch
[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
9ff2f060 10TEST_PASSES_SANITIZE_LEAK=true
190f5323 11. ./test-lib.sh
21828964 12
2ea3c171
TR
13log_with_names () {
14 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
34ae3b70 15 git name-rev --annotate-stdin --name-only --refs=refs/heads/$1
2ea3c171
TR
16}
17
18
190f5323 19test_expect_success 'prepare repository' '
f7951e1d
JS
20 test_commit 1 A &&
21 test_commit 2 A &&
190f5323
TR
22 git symbolic-ref HEAD refs/heads/other &&
23 rm .git/index &&
f7951e1d
JS
24 test_commit 3 B &&
25 test_commit 1b A 1 &&
26 test_commit 4 B
190f5323
TR
27'
28
f2b6a199
MZ
29test_expect_success 'rebase --root fails with too many args' '
30 git checkout -B fail other &&
d1c02d93 31 test_must_fail git rebase --onto main --root fail fail
f2b6a199
MZ
32'
33
190f5323 34test_expect_success 'setup pre-rebase hook' '
c36c6285
ÆAB
35 test_hook --setup pre-rebase <<-\EOF
36 echo "$1,$2" >.git/PRE-REBASE-INPUT
37 EOF
190f5323
TR
38'
39cat > expect <<EOF
404
413
422
431
44EOF
45
46test_expect_success 'rebase --root --onto <newbase>' '
f2b6a199 47 git checkout -b work other &&
d1c02d93 48 git rebase --root --onto main &&
190f5323
TR
49 git log --pretty=tformat:"%s" > rebased &&
50 test_cmp expect rebased
51'
52
53test_expect_success 'pre-rebase got correct input (1)' '
54 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
55'
56
57test_expect_success 'rebase --root --onto <newbase> <branch>' '
58 git branch work2 other &&
d1c02d93 59 git rebase --root --onto main work2 &&
190f5323
TR
60 git log --pretty=tformat:"%s" > rebased2 &&
61 test_cmp expect rebased2
62'
63
64test_expect_success 'pre-rebase got correct input (2)' '
65 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
66'
67
d911d146
TR
68test_expect_success 'rebase -i --root --onto <newbase>' '
69 git checkout -b work3 other &&
d1c02d93 70 git rebase -i --root --onto main &&
d911d146
TR
71 git log --pretty=tformat:"%s" > rebased3 &&
72 test_cmp expect rebased3
73'
74
75test_expect_success 'pre-rebase got correct input (3)' '
76 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
77'
78
79test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
80 git branch work4 other &&
d1c02d93 81 git rebase -i --root --onto main work4 &&
d911d146
TR
82 git log --pretty=tformat:"%s" > rebased4 &&
83 test_cmp expect rebased4
84'
85
86test_expect_success 'pre-rebase got correct input (4)' '
87 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
88'
89
d911d146
TR
90test_expect_success 'set up merge history' '
91 git checkout other^ &&
92 git checkout -b side &&
f7951e1d 93 test_commit 5 C &&
d911d146
TR
94 git checkout other &&
95 git merge side
96'
97
2ea3c171
TR
98cat > expect-side <<'EOF'
99commit work6 work6~1 work6^2
100Merge branch 'side' into other
101commit work6^2 work6~2
1025
103commit work6~1 work6~2
1044
105commit work6~2 work6~3
1063
107commit work6~3 work6~4
1082
109commit work6~4
1101
d911d146
TR
111EOF
112
d911d146
TR
113test_expect_success 'set up second root and merge' '
114 git symbolic-ref HEAD refs/heads/third &&
115 rm .git/index &&
116 rm A B C &&
f7951e1d 117 test_commit 6 D &&
d911d146 118 git checkout other &&
e379fdf3 119 git merge --allow-unrelated-histories third
d911d146
TR
120'
121
2ea3c171
TR
122cat > expect-third <<'EOF'
123commit work7 work7~1 work7^2
124Merge branch 'third' into other
125commit work7^2 work7~4
1266
127commit work7~1 work7~2 work7~1^2
128Merge branch 'side' into other
129commit work7~1^2 work7~3
1305
131commit work7~2 work7~3
1324
133commit work7~3 work7~4
1343
135commit work7~4 work7~5
1362
137commit work7~5
1381
d911d146
TR
139EOF
140
190f5323 141test_expect_success 'setup pre-rebase hook that fails' '
c36c6285
ÆAB
142 test_hook --setup --clobber pre-rebase <<-\EOF
143 false
144 EOF
190f5323
TR
145'
146
147test_expect_success 'pre-rebase hook stops rebase' '
148 git checkout -b stops1 other &&
d1c02d93 149 test_must_fail git rebase --root --onto main &&
a48fcd83 150 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
190f5323
TR
151 test 0 = $(git rev-list other...stops1 | wc -l)
152'
153
d911d146
TR
154test_expect_success 'pre-rebase hook stops rebase -i' '
155 git checkout -b stops2 other &&
d1c02d93 156 test_must_fail git rebase --root --onto main &&
a48fcd83 157 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
d911d146
TR
158 test 0 = $(git rev-list other...stops2 | wc -l)
159'
160
a6c7a276
JH
161test_expect_success 'remove pre-rebase hook' '
162 rm -f .git/hooks/pre-rebase
163'
164
165test_expect_success 'set up a conflict' '
d1c02d93 166 git checkout main &&
a6c7a276
JH
167 echo conflict > B &&
168 git add B &&
169 git commit -m conflict
170'
171
172test_expect_success 'rebase --root with conflict (first part)' '
173 git checkout -b conflict1 other &&
d1c02d93 174 test_must_fail git rebase --root --onto main &&
a6c7a276
JH
175 git ls-files -u | grep "B$"
176'
177
178test_expect_success 'fix the conflict' '
179 echo 3 > B &&
180 git add B
181'
182
183cat > expect-conflict <<EOF
1846
1855
1864
1873
188conflict
1892
1901
191EOF
192
193test_expect_success 'rebase --root with conflict (second part)' '
194 git rebase --continue &&
195 git log --pretty=tformat:"%s" > conflict1 &&
196 test_cmp expect-conflict conflict1
197'
198
199test_expect_success 'rebase -i --root with conflict (first part)' '
200 git checkout -b conflict2 other &&
d1c02d93 201 test_must_fail git rebase -i --root --onto main &&
a6c7a276
JH
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
210test_expect_success 'rebase -i --root with conflict (second part)' '
211 git rebase --continue &&
212 git log --pretty=tformat:"%s" > conflict2 &&
213 test_cmp expect-conflict conflict2
214'
215
216cat >expect-conflict-p <<\EOF
217commit conflict3 conflict3~1 conflict3^2
218Merge branch 'third' into other
219commit conflict3^2 conflict3~4
2206
221commit conflict3~1 conflict3~2 conflict3~1^2
222Merge branch 'side' into other
223commit conflict3~1^2 conflict3~3
2245
225commit conflict3~2 conflict3~3
2264
227commit conflict3~3 conflict3~4
2283
229commit conflict3~4 conflict3~5
230conflict
231commit conflict3~5 conflict3~6
2322
233commit conflict3~6
2341
235EOF
236
a6c7a276
JH
237test_expect_success 'fix the conflict' '
238 echo 3 > B &&
239 git add B
240'
241
190f5323 242test_done