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' '
16 git symbolic-ref HEAD refs/heads/other &&
29 test_expect_success
'rebase --root expects --onto' '
30 test_must_fail git rebase --root
33 test_expect_success
'setup pre-rebase hook' '
34 mkdir -p .git/hooks &&
35 cat >.git/hooks/pre-rebase <<EOF &&
37 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
39 chmod +x .git/hooks/pre-rebase
48 test_expect_success
'rebase --root --onto <newbase>' '
49 git checkout -b work &&
50 git rebase --root --onto master &&
51 git log --pretty=tformat:"%s" > rebased &&
52 test_cmp expect rebased
55 test_expect_success
'pre-rebase got correct input (1)' '
56 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
59 test_expect_success
'rebase --root --onto <newbase> <branch>' '
60 git branch work2 other &&
61 git rebase --root --onto master work2 &&
62 git log --pretty=tformat:"%s" > rebased2 &&
63 test_cmp expect rebased2
66 test_expect_success
'pre-rebase got correct input (2)' '
67 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
70 test_expect_success
'rebase -i --root --onto <newbase>' '
71 git checkout -b work3 other &&
72 GIT_EDITOR=: git rebase -i --root --onto master &&
73 git log --pretty=tformat:"%s" > rebased3 &&
74 test_cmp expect rebased3
77 test_expect_success
'pre-rebase got correct input (3)' '
78 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
81 test_expect_success
'rebase -i --root --onto <newbase> <branch>' '
82 git branch work4 other &&
83 GIT_EDITOR=: git rebase -i --root --onto master work4 &&
84 git log --pretty=tformat:"%s" > rebased4 &&
85 test_cmp expect rebased4
88 test_expect_success
'pre-rebase got correct input (4)' '
89 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
92 test_expect_success
'rebase -i -p with linear history' '
93 git checkout -b work5 other &&
94 GIT_EDITOR=: git rebase -i -p --root --onto master &&
95 git log --pretty=tformat:"%s" > rebased5 &&
96 test_cmp expect rebased5
99 test_expect_success
'pre-rebase got correct input (5)' '
100 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
103 test_expect_success
'set up merge history' '
104 git checkout other^ &&
105 git checkout -b side &&
109 git checkout other &&
113 sed 's/#/ /g' > expect-side
<<'EOF'
114 * Merge branch 'side' into other
124 test_expect_success
'rebase -i -p with merge' '
125 git checkout -b work6 other &&
126 GIT_EDITOR=: git rebase -i -p --root --onto master &&
127 git log --graph --topo-order --pretty=tformat:"%s" > rebased6 &&
128 test_cmp expect-side rebased6
131 test_expect_success
'set up second root and merge' '
132 git symbolic-ref HEAD refs/heads/third &&
138 git checkout other &&
142 sed 's/#/ /g' > expect-third
<<'EOF'
143 * Merge branch 'third' into other
146 * | Merge branch 'side' into other
157 test_expect_success
'rebase -i -p with two roots' '
158 git checkout -b work7 other &&
159 GIT_EDITOR=: git rebase -i -p --root --onto master &&
160 git log --graph --topo-order --pretty=tformat:"%s" > 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 &&
170 chmod +x .git/hooks/pre-rebase
173 test_expect_success
'pre-rebase hook stops rebase' '
174 git checkout -b stops1 other &&
178 test_must_fail git rebase --root --onto master
180 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
181 test 0 = $(git rev-list other...stops1 | wc -l)
184 test_expect_success
'pre-rebase hook stops rebase -i' '
185 git checkout -b stops2 other &&
189 test_must_fail git rebase --root --onto master
191 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2
192 test 0 = $(git rev-list other...stops2 | wc -l)
195 test_expect_success
'remove pre-rebase hook' '
196 rm -f .git/hooks/pre-rebase
199 test_expect_success
'set up a conflict' '
200 git checkout master &&
203 git commit -m conflict
206 test_expect_success
'rebase --root with conflict (first part)' '
207 git checkout -b conflict1 other &&
208 test_must_fail git rebase --root --onto master &&
209 git ls-files -u | grep "B$"
212 test_expect_success
'fix the conflict' '
217 cat > expect-conflict
<<EOF
227 test_expect_success
'rebase --root with conflict (second part)' '
228 git rebase --continue &&
229 git log --pretty=tformat:"%s" > conflict1 &&
230 test_cmp expect-conflict conflict1
233 test_expect_success
'rebase -i --root with conflict (first part)' '
234 git checkout -b conflict2 other &&
238 test_must_fail git rebase -i --root --onto master
240 git ls-files -u | grep "B$"
243 test_expect_success
'fix the conflict' '
248 test_expect_success
'rebase -i --root with conflict (second part)' '
249 git rebase --continue &&
250 git log --pretty=tformat:"%s" > conflict2 &&
251 test_cmp expect-conflict conflict2
254 cat >expect-conflict-p
<<\EOF
255 commit conflict3 conflict3~
1 conflict3^
2
256 Merge branch
'third' into other
257 commit conflict3^
2 conflict3~
4
259 commit conflict3~
1 conflict3~
2 conflict3~
1^
2
260 Merge branch
'side' into other
261 commit conflict3~
1^
2 conflict3~
3
263 commit conflict3~
2 conflict3~
3
265 commit conflict3~
3 conflict3~
4
267 commit conflict3~
4 conflict3~
5
269 commit conflict3~
5 conflict3~
6
275 test_expect_success
'rebase -i -p --root with conflict (first part)' '
276 git checkout -b conflict3 other &&
280 test_must_fail git rebase -i -p --root --onto master
282 git ls-files -u | grep "B$"
285 test_expect_success
'fix the conflict' '
290 test_expect_success
'rebase -i -p --root with conflict (second part)' '
291 git rebase --continue &&
292 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
293 git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
294 test_cmp expect-conflict-p out