Basic build infrastructure for Python scripts
[alt-git.git] / t / t3412-rebase-root.sh
blob5869061c5bfdee4a84b156b8ec9d6e331a2c906c
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 expects --onto' '
26 test_must_fail git rebase --root
29 test_expect_success 'setup pre-rebase hook' '
30 mkdir -p .git/hooks &&
31 cat >.git/hooks/pre-rebase <<EOF &&
32 #!$SHELL_PATH
33 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
34 EOF
35 chmod +x .git/hooks/pre-rebase
37 cat > expect <<EOF
42 EOF
44 test_expect_success 'rebase --root --onto <newbase>' '
45 git checkout -b work &&
46 git rebase --root --onto master &&
47 git log --pretty=tformat:"%s" > rebased &&
48 test_cmp expect rebased
51 test_expect_success 'pre-rebase got correct input (1)' '
52 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
55 test_expect_success 'rebase --root --onto <newbase> <branch>' '
56 git branch work2 other &&
57 git rebase --root --onto master work2 &&
58 git log --pretty=tformat:"%s" > rebased2 &&
59 test_cmp expect rebased2
62 test_expect_success 'pre-rebase got correct input (2)' '
63 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
66 test_expect_success 'rebase -i --root --onto <newbase>' '
67 git checkout -b work3 other &&
68 git rebase -i --root --onto master &&
69 git log --pretty=tformat:"%s" > rebased3 &&
70 test_cmp expect rebased3
73 test_expect_success 'pre-rebase got correct input (3)' '
74 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
77 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
78 git branch work4 other &&
79 git rebase -i --root --onto master work4 &&
80 git log --pretty=tformat:"%s" > rebased4 &&
81 test_cmp expect rebased4
84 test_expect_success 'pre-rebase got correct input (4)' '
85 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
88 test_expect_success 'rebase -i -p with linear history' '
89 git checkout -b work5 other &&
90 git rebase -i -p --root --onto master &&
91 git log --pretty=tformat:"%s" > rebased5 &&
92 test_cmp expect rebased5
95 test_expect_success 'pre-rebase got correct input (5)' '
96 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
99 test_expect_success 'set up merge history' '
100 git checkout other^ &&
101 git checkout -b side &&
102 test_commit 5 C &&
103 git checkout other &&
104 git merge side
107 cat > expect-side <<'EOF'
108 commit work6 work6~1 work6^2
109 Merge branch 'side' into other
110 commit work6^2 work6~2
112 commit work6~1 work6~2
114 commit work6~2 work6~3
116 commit work6~3 work6~4
118 commit work6~4
122 test_expect_success 'rebase -i -p with merge' '
123 git checkout -b work6 other &&
124 git rebase -i -p --root --onto master &&
125 log_with_names work6 > rebased6 &&
126 test_cmp expect-side rebased6
129 test_expect_success 'set up second root and merge' '
130 git symbolic-ref HEAD refs/heads/third &&
131 rm .git/index &&
132 rm A B C &&
133 test_commit 6 D &&
134 git checkout other &&
135 git merge third
138 cat > expect-third <<'EOF'
139 commit work7 work7~1 work7^2
140 Merge branch 'third' into other
141 commit work7^2 work7~4
143 commit work7~1 work7~2 work7~1^2
144 Merge branch 'side' into other
145 commit work7~1^2 work7~3
147 commit work7~2 work7~3
149 commit work7~3 work7~4
151 commit work7~4 work7~5
153 commit work7~5
157 test_expect_success 'rebase -i -p with two roots' '
158 git checkout -b work7 other &&
159 git rebase -i -p --root --onto master &&
160 log_with_names work7 > rebased7 &&
161 test_cmp expect-third rebased7
164 test_expect_success 'setup pre-rebase hook that fails' '
165 mkdir -p .git/hooks &&
166 cat >.git/hooks/pre-rebase <<EOF &&
167 #!$SHELL_PATH
168 false
170 chmod +x .git/hooks/pre-rebase
173 test_expect_success 'pre-rebase hook stops rebase' '
174 git checkout -b stops1 other &&
175 test_must_fail git rebase --root --onto master &&
176 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
177 test 0 = $(git rev-list other...stops1 | wc -l)
180 test_expect_success 'pre-rebase hook stops rebase -i' '
181 git checkout -b stops2 other &&
182 test_must_fail git rebase --root --onto master &&
183 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2
184 test 0 = $(git rev-list other...stops2 | wc -l)
187 test_expect_success 'remove pre-rebase hook' '
188 rm -f .git/hooks/pre-rebase
191 test_expect_success 'set up a conflict' '
192 git checkout master &&
193 echo conflict > B &&
194 git add B &&
195 git commit -m conflict
198 test_expect_success 'rebase --root with conflict (first part)' '
199 git checkout -b conflict1 other &&
200 test_must_fail git rebase --root --onto master &&
201 git ls-files -u | grep "B$"
204 test_expect_success 'fix the conflict' '
205 echo 3 > B &&
206 git add B
209 cat > expect-conflict <<EOF
214 conflict
219 test_expect_success 'rebase --root with conflict (second part)' '
220 git rebase --continue &&
221 git log --pretty=tformat:"%s" > conflict1 &&
222 test_cmp expect-conflict conflict1
225 test_expect_success 'rebase -i --root with conflict (first part)' '
226 git checkout -b conflict2 other &&
227 test_must_fail git rebase -i --root --onto master &&
228 git ls-files -u | grep "B$"
231 test_expect_success 'fix the conflict' '
232 echo 3 > B &&
233 git add B
236 test_expect_success 'rebase -i --root with conflict (second part)' '
237 git rebase --continue &&
238 git log --pretty=tformat:"%s" > conflict2 &&
239 test_cmp expect-conflict conflict2
242 cat >expect-conflict-p <<\EOF
243 commit conflict3 conflict3~1 conflict3^2
244 Merge branch 'third' into other
245 commit conflict3^2 conflict3~4
247 commit conflict3~1 conflict3~2 conflict3~1^2
248 Merge branch 'side' into other
249 commit conflict3~1^2 conflict3~3
251 commit conflict3~2 conflict3~3
253 commit conflict3~3 conflict3~4
255 commit conflict3~4 conflict3~5
256 conflict
257 commit conflict3~5 conflict3~6
259 commit conflict3~6
263 test_expect_success 'rebase -i -p --root with conflict (first part)' '
264 git checkout -b conflict3 other &&
265 test_must_fail git rebase -i -p --root --onto master &&
266 git ls-files -u | grep "B$"
269 test_expect_success 'fix the conflict' '
270 echo 3 > B &&
271 git add B
274 test_expect_success 'rebase -i -p --root with conflict (second part)' '
275 git rebase --continue &&
276 log_with_names conflict3 >out &&
277 test_cmp expect-conflict-p out
280 test_done