archive: handle commits with an empty tree
[git/jnareb-git.git] / t / t3412-rebase-root.sh
blob0b521057283bf106da8ce55f25f61c7ec7e3ad35
1 #!/bin/sh
3 test_description='git rebase --root
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
7 . ./test-lib.sh
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
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
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
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
38 cat > expect <<EOF
43 EOF
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
52 test_expect_success 'pre-rebase got correct input (1)' '
53 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
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
63 test_expect_success 'pre-rebase got correct input (2)' '
64 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
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
74 test_expect_success 'pre-rebase got correct input (3)' '
75 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
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
85 test_expect_success 'pre-rebase got correct input (4)' '
86 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
89 test_expect_success '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
96 test_expect_success 'pre-rebase got correct input (5)' '
97 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
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
108 cat > expect-side <<'EOF'
109 commit work6 work6~1 work6^2
110 Merge branch 'side' into other
111 commit work6^2 work6~2
113 commit work6~1 work6~2
115 commit work6~2 work6~3
117 commit work6~3 work6~4
119 commit work6~4
123 test_expect_success '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
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 third
139 cat > expect-third <<'EOF'
140 commit work7 work7~1 work7^2
141 Merge branch 'third' into other
142 commit work7^2 work7~4
144 commit work7~1 work7~2 work7~1^2
145 Merge branch 'side' into other
146 commit work7~1^2 work7~3
148 commit work7~2 work7~3
150 commit work7~3 work7~4
152 commit work7~4 work7~5
154 commit work7~5
158 test_expect_success '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
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
171 chmod +x .git/hooks/pre-rebase
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)
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)
188 test_expect_success 'remove pre-rebase hook' '
189 rm -f .git/hooks/pre-rebase
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
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$"
205 test_expect_success 'fix the conflict' '
206 echo 3 > B &&
207 git add B
210 cat > expect-conflict <<EOF
215 conflict
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
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$"
232 test_expect_success 'fix the conflict' '
233 echo 3 > B &&
234 git add B
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
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
248 commit conflict3~1 conflict3~2 conflict3~1^2
249 Merge branch 'side' into other
250 commit conflict3~1^2 conflict3~3
252 commit conflict3~2 conflict3~3
254 commit conflict3~3 conflict3~4
256 commit conflict3~4 conflict3~5
257 conflict
258 commit conflict3~5 conflict3~6
260 commit conflict3~6
264 test_expect_success '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$"
270 test_expect_success 'fix the conflict' '
271 echo 3 > B &&
272 git add B
275 test_expect_success '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
281 test_done