Fix 'git diff --no-index' with a non-existing symlink target
[4msysgit-hv.git] / t / t3412-rebase-root.sh
blob9fc528fdea18409fa2871f62ec3b14577b1a55e4
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 test_expect_success 'prepare repository' '
10 test_commit 1 A &&
11 test_commit 2 A &&
12 git symbolic-ref HEAD refs/heads/other &&
13 rm .git/index &&
14 test_commit 3 B &&
15 test_commit 1b A 1 &&
16 test_commit 4 B
19 test_expect_success 'rebase --root expects --onto' '
20 test_must_fail git rebase --root
23 test_expect_success 'setup pre-rebase hook' '
24 mkdir -p .git/hooks &&
25 cat >.git/hooks/pre-rebase <<EOF &&
26 #!$SHELL_PATH
27 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
28 EOF
29 chmod +x .git/hooks/pre-rebase
31 cat > expect <<EOF
36 EOF
38 test_expect_success 'rebase --root --onto <newbase>' '
39 git checkout -b work &&
40 git rebase --root --onto master &&
41 git log --pretty=tformat:"%s" > rebased &&
42 test_cmp expect rebased
45 test_expect_success 'pre-rebase got correct input (1)' '
46 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
49 test_expect_success 'rebase --root --onto <newbase> <branch>' '
50 git branch work2 other &&
51 git rebase --root --onto master work2 &&
52 git log --pretty=tformat:"%s" > rebased2 &&
53 test_cmp expect rebased2
56 test_expect_success 'pre-rebase got correct input (2)' '
57 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
60 test_expect_success 'rebase -i --root --onto <newbase>' '
61 git checkout -b work3 other &&
62 GIT_EDITOR=: git rebase -i --root --onto master &&
63 git log --pretty=tformat:"%s" > rebased3 &&
64 test_cmp expect rebased3
67 test_expect_success 'pre-rebase got correct input (3)' '
68 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
71 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
72 git branch work4 other &&
73 GIT_EDITOR=: git rebase -i --root --onto master work4 &&
74 git log --pretty=tformat:"%s" > rebased4 &&
75 test_cmp expect rebased4
78 test_expect_success 'pre-rebase got correct input (4)' '
79 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
82 test_expect_success 'rebase -i -p with linear history' '
83 git checkout -b work5 other &&
84 GIT_EDITOR=: git rebase -i -p --root --onto master &&
85 git log --pretty=tformat:"%s" > rebased5 &&
86 test_cmp expect rebased5
89 test_expect_success 'pre-rebase got correct input (5)' '
90 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
93 test_expect_success 'set up merge history' '
94 git checkout other^ &&
95 git checkout -b side &&
96 test_commit 5 C &&
97 git checkout other &&
98 git merge side
101 sed 's/#/ /g' > expect-side <<'EOF'
102 * Merge branch 'side' into other
103 |\##
104 | * 5
105 * | 4
106 |/##
112 test_expect_success 'rebase -i -p with merge' '
113 git checkout -b work6 other &&
114 GIT_EDITOR=: git rebase -i -p --root --onto master &&
115 git log --graph --topo-order --pretty=tformat:"%s" > rebased6 &&
116 test_cmp expect-side rebased6
119 test_expect_success 'set up second root and merge' '
120 git symbolic-ref HEAD refs/heads/third &&
121 rm .git/index &&
122 rm A B C &&
123 test_commit 6 D &&
124 git checkout other &&
125 git merge third
128 sed 's/#/ /g' > expect-third <<'EOF'
129 * Merge branch 'third' into other
130 |\##
131 | * 6
132 * | Merge branch 'side' into other
133 |\ \##
134 | * | 5
135 * | | 4
136 |/ /##
137 * | 3
138 |/##
143 test_expect_success 'rebase -i -p with two roots' '
144 git checkout -b work7 other &&
145 GIT_EDITOR=: git rebase -i -p --root --onto master &&
146 git log --graph --topo-order --pretty=tformat:"%s" > rebased7 &&
147 test_cmp expect-third rebased7
150 test_expect_success 'setup pre-rebase hook that fails' '
151 mkdir -p .git/hooks &&
152 cat >.git/hooks/pre-rebase <<EOF &&
153 #!$SHELL_PATH
154 false
156 chmod +x .git/hooks/pre-rebase
159 test_expect_success 'pre-rebase hook stops rebase' '
160 git checkout -b stops1 other &&
162 GIT_EDITOR=:
163 export GIT_EDITOR
164 test_must_fail git rebase --root --onto master
165 ) &&
166 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
167 test 0 = $(git rev-list other...stops1 | wc -l)
170 test_expect_success 'pre-rebase hook stops rebase -i' '
171 git checkout -b stops2 other &&
173 GIT_EDITOR=:
174 export GIT_EDITOR
175 test_must_fail git rebase --root --onto master
176 ) &&
177 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2
178 test 0 = $(git rev-list other...stops2 | wc -l)
181 test_expect_success 'remove pre-rebase hook' '
182 rm -f .git/hooks/pre-rebase
185 test_expect_success 'set up a conflict' '
186 git checkout master &&
187 echo conflict > B &&
188 git add B &&
189 git commit -m conflict
192 test_expect_success 'rebase --root with conflict (first part)' '
193 git checkout -b conflict1 other &&
194 test_must_fail git rebase --root --onto master &&
195 git ls-files -u | grep "B$"
198 test_expect_success 'fix the conflict' '
199 echo 3 > B &&
200 git add B
203 cat > expect-conflict <<EOF
208 conflict
213 test_expect_success 'rebase --root with conflict (second part)' '
214 git rebase --continue &&
215 git log --pretty=tformat:"%s" > conflict1 &&
216 test_cmp expect-conflict conflict1
219 test_expect_success 'rebase -i --root with conflict (first part)' '
220 git checkout -b conflict2 other &&
222 GIT_EDITOR=:
223 export GIT_EDITOR
224 test_must_fail git rebase -i --root --onto master
225 ) &&
226 git ls-files -u | grep "B$"
229 test_expect_success 'fix the conflict' '
230 echo 3 > B &&
231 git add B
234 test_expect_success 'rebase -i --root with conflict (second part)' '
235 git rebase --continue &&
236 git log --pretty=tformat:"%s" > conflict2 &&
237 test_cmp expect-conflict conflict2
240 cat >expect-conflict-p <<\EOF
241 commit conflict3 conflict3~1 conflict3^2
242 Merge branch 'third' into other
243 commit conflict3^2 conflict3~4
245 commit conflict3~1 conflict3~2 conflict3~1^2
246 Merge branch 'side' into other
247 commit conflict3~1^2 conflict3~3
249 commit conflict3~2 conflict3~3
251 commit conflict3~3 conflict3~4
253 commit conflict3~4 conflict3~5
254 conflict
255 commit conflict3~5 conflict3~6
257 commit conflict3~6
261 test_expect_success 'rebase -i -p --root with conflict (first part)' '
262 git checkout -b conflict3 other &&
264 GIT_EDITOR=:
265 export GIT_EDITOR
266 test_must_fail git rebase -i -p --root --onto master
267 ) &&
268 git ls-files -u | grep "B$"
271 test_expect_success 'fix the conflict' '
272 echo 3 > B &&
273 git add B
276 test_expect_success 'rebase -i -p --root with conflict (second part)' '
277 git rebase --continue &&
278 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
279 git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
280 test_cmp expect-conflict-p out
283 test_done