]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3412-rebase-root.sh
l10n: fr v2.23.0 round 2
[thirdparty/git.git] / t / t3412-rebase-root.sh
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
9 log_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
15 test_expect_success 'prepare repository' '
16 test_commit 1 A &&
17 test_commit 2 A &&
18 git symbolic-ref HEAD refs/heads/other &&
19 rm .git/index &&
20 test_commit 3 B &&
21 test_commit 1b A 1 &&
22 test_commit 4 B
23 '
24
25 test_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
30 test_expect_success 'setup pre-rebase hook' '
31 mkdir -p .git/hooks &&
32 cat >.git/hooks/pre-rebase <<EOF &&
33 #!$SHELL_PATH
34 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
35 EOF
36 chmod +x .git/hooks/pre-rebase
37 '
38 cat > expect <<EOF
39 4
40 3
41 2
42 1
43 EOF
44
45 test_expect_success 'rebase --root --onto <newbase>' '
46 git checkout -b work other &&
47 git rebase --root --onto master &&
48 git log --pretty=tformat:"%s" > rebased &&
49 test_cmp expect rebased
50 '
51
52 test_expect_success 'pre-rebase got correct input (1)' '
53 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
54 '
55
56 test_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
63 test_expect_success 'pre-rebase got correct input (2)' '
64 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
65 '
66
67 test_expect_success 'rebase -i --root --onto <newbase>' '
68 git checkout -b work3 other &&
69 git rebase -i --root --onto master &&
70 git log --pretty=tformat:"%s" > rebased3 &&
71 test_cmp expect rebased3
72 '
73
74 test_expect_success 'pre-rebase got correct input (3)' '
75 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
76 '
77
78 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
79 git branch work4 other &&
80 git rebase -i --root --onto master work4 &&
81 git log --pretty=tformat:"%s" > rebased4 &&
82 test_cmp expect rebased4
83 '
84
85 test_expect_success 'pre-rebase got correct input (4)' '
86 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
87 '
88
89 test_expect_success REBASE_P 'rebase -i -p with linear history' '
90 git checkout -b work5 other &&
91 git rebase -i -p --root --onto master &&
92 git log --pretty=tformat:"%s" > rebased5 &&
93 test_cmp expect rebased5
94 '
95
96 test_expect_success REBASE_P 'pre-rebase got correct input (5)' '
97 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
98 '
99
100 test_expect_success 'set up merge history' '
101 git checkout other^ &&
102 git checkout -b side &&
103 test_commit 5 C &&
104 git checkout other &&
105 git merge side
106 '
107
108 cat > expect-side <<'EOF'
109 commit work6 work6~1 work6^2
110 Merge branch 'side' into other
111 commit work6^2 work6~2
112 5
113 commit work6~1 work6~2
114 4
115 commit work6~2 work6~3
116 3
117 commit work6~3 work6~4
118 2
119 commit work6~4
120 1
121 EOF
122
123 test_expect_success REBASE_P 'rebase -i -p with merge' '
124 git checkout -b work6 other &&
125 git rebase -i -p --root --onto master &&
126 log_with_names work6 > rebased6 &&
127 test_cmp expect-side rebased6
128 '
129
130 test_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 &&
134 test_commit 6 D &&
135 git checkout other &&
136 git merge --allow-unrelated-histories third
137 '
138
139 cat > expect-third <<'EOF'
140 commit work7 work7~1 work7^2
141 Merge branch 'third' into other
142 commit work7^2 work7~4
143 6
144 commit work7~1 work7~2 work7~1^2
145 Merge branch 'side' into other
146 commit work7~1^2 work7~3
147 5
148 commit work7~2 work7~3
149 4
150 commit work7~3 work7~4
151 3
152 commit work7~4 work7~5
153 2
154 commit work7~5
155 1
156 EOF
157
158 test_expect_success REBASE_P 'rebase -i -p with two roots' '
159 git checkout -b work7 other &&
160 git rebase -i -p --root --onto master &&
161 log_with_names work7 > rebased7 &&
162 test_cmp expect-third rebased7
163 '
164
165 test_expect_success 'setup pre-rebase hook that fails' '
166 mkdir -p .git/hooks &&
167 cat >.git/hooks/pre-rebase <<EOF &&
168 #!$SHELL_PATH
169 false
170 EOF
171 chmod +x .git/hooks/pre-rebase
172 '
173
174 test_expect_success 'pre-rebase hook stops rebase' '
175 git checkout -b stops1 other &&
176 test_must_fail git rebase --root --onto master &&
177 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
178 test 0 = $(git rev-list other...stops1 | wc -l)
179 '
180
181 test_expect_success 'pre-rebase hook stops rebase -i' '
182 git checkout -b stops2 other &&
183 test_must_fail git rebase --root --onto master &&
184 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
185 test 0 = $(git rev-list other...stops2 | wc -l)
186 '
187
188 test_expect_success 'remove pre-rebase hook' '
189 rm -f .git/hooks/pre-rebase
190 '
191
192 test_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
199 test_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
205 test_expect_success 'fix the conflict' '
206 echo 3 > B &&
207 git add B
208 '
209
210 cat > expect-conflict <<EOF
211 6
212 5
213 4
214 3
215 conflict
216 2
217 1
218 EOF
219
220 test_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
226 test_expect_success 'rebase -i --root with conflict (first part)' '
227 git checkout -b conflict2 other &&
228 test_must_fail git rebase -i --root --onto master &&
229 git ls-files -u | grep "B$"
230 '
231
232 test_expect_success 'fix the conflict' '
233 echo 3 > B &&
234 git add B
235 '
236
237 test_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
243 cat >expect-conflict-p <<\EOF
244 commit conflict3 conflict3~1 conflict3^2
245 Merge branch 'third' into other
246 commit conflict3^2 conflict3~4
247 6
248 commit conflict3~1 conflict3~2 conflict3~1^2
249 Merge branch 'side' into other
250 commit conflict3~1^2 conflict3~3
251 5
252 commit conflict3~2 conflict3~3
253 4
254 commit conflict3~3 conflict3~4
255 3
256 commit conflict3~4 conflict3~5
257 conflict
258 commit conflict3~5 conflict3~6
259 2
260 commit conflict3~6
261 1
262 EOF
263
264 test_expect_success REBASE_P 'rebase -i -p --root with conflict (first part)' '
265 git checkout -b conflict3 other &&
266 test_must_fail git rebase -i -p --root --onto master &&
267 git ls-files -u | grep "B$"
268 '
269
270 test_expect_success 'fix the conflict' '
271 echo 3 > B &&
272 git add B
273 '
274
275 test_expect_success REBASE_P 'rebase -i -p --root with conflict (second part)' '
276 git rebase --continue &&
277 log_with_names conflict3 >out &&
278 test_cmp expect-conflict-p out
279 '
280
281 test_done