3 test_description
='git rebase --root
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
9 test_expect_success
'prepare repository' '
12 git symbolic-ref HEAD refs/heads/other &&
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 &&
27 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
29 chmod +x .git/hooks/pre-rebase
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 &&
101 sed 's/#/ /g' > expect-side
<<'EOF'
102 * Merge branch 'side' into other
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 &&
124 git checkout other &&
128 sed 's/#/ /g' > expect-third
<<'EOF'
129 * Merge branch 'third' into other
132 * | Merge branch 'side' into other
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 &&
156 chmod +x .git/hooks/pre-rebase
159 test_expect_success
'pre-rebase hook stops rebase' '
160 git checkout -b stops1 other &&
164 test_must_fail git rebase --root --onto master
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 &&
175 test_must_fail git rebase --root --onto master
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 &&
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' '
203 cat > expect-conflict
<<EOF
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 &&
224 test_must_fail git rebase -i --root --onto master
226 git ls-files -u | grep "B$"
229 test_expect_success
'fix the conflict' '
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
255 commit conflict3~
5 conflict3~
6
261 test_expect_success
'rebase -i -p --root with conflict (first part)' '
262 git checkout -b conflict3 other &&
266 test_must_fail git rebase -i -p --root --onto master
268 git ls-files -u | grep "B$"
271 test_expect_success
'fix the conflict' '
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