3 test_description
='git rebase --root
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
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' '
18 git symbolic-ref HEAD refs/heads/other &&
25 test_expect_success
'rebase --root expects --onto' '
26 git checkout -B fail other &&
27 test_must_fail git rebase --root
30 test_expect_success
'rebase --root fails with too many args' '
31 git checkout -B fail other &&
32 test_must_fail git rebase --onto master --root fail fail
35 test_expect_success
'setup pre-rebase hook' '
36 mkdir -p .git/hooks &&
37 cat >.git/hooks/pre-rebase <<EOF &&
39 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
41 chmod +x .git/hooks/pre-rebase
50 test_expect_success
'rebase --root --onto <newbase>' '
51 git checkout -b work other &&
52 git rebase --root --onto master &&
53 git log --pretty=tformat:"%s" > rebased &&
54 test_cmp expect rebased
57 test_expect_success
'pre-rebase got correct input (1)' '
58 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
61 test_expect_success
'rebase --root --onto <newbase> <branch>' '
62 git branch work2 other &&
63 git rebase --root --onto master work2 &&
64 git log --pretty=tformat:"%s" > rebased2 &&
65 test_cmp expect rebased2
68 test_expect_success
'pre-rebase got correct input (2)' '
69 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
72 test_expect_success
'rebase -i --root --onto <newbase>' '
73 git checkout -b work3 other &&
74 git rebase -i --root --onto master &&
75 git log --pretty=tformat:"%s" > rebased3 &&
76 test_cmp expect rebased3
79 test_expect_success
'pre-rebase got correct input (3)' '
80 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
83 test_expect_success
'rebase -i --root --onto <newbase> <branch>' '
84 git branch work4 other &&
85 git rebase -i --root --onto master work4 &&
86 git log --pretty=tformat:"%s" > rebased4 &&
87 test_cmp expect rebased4
90 test_expect_success
'pre-rebase got correct input (4)' '
91 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
94 test_expect_success
'rebase -i -p with linear history' '
95 git checkout -b work5 other &&
96 git rebase -i -p --root --onto master &&
97 git log --pretty=tformat:"%s" > rebased5 &&
98 test_cmp expect rebased5
101 test_expect_success
'pre-rebase got correct input (5)' '
102 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
105 test_expect_success
'set up merge history' '
106 git checkout other^ &&
107 git checkout -b side &&
109 git checkout other &&
113 cat > expect-side
<<'EOF'
114 commit work6 work6~1 work6^2
115 Merge branch 'side' into other
116 commit work6^2 work6~2
118 commit work6~1 work6~2
120 commit work6~2 work6~3
122 commit work6~3 work6~4
128 test_expect_success
'rebase -i -p with merge' '
129 git checkout -b work6 other &&
130 git rebase -i -p --root --onto master &&
131 log_with_names work6 > rebased6 &&
132 test_cmp expect-side rebased6
135 test_expect_success
'set up second root and merge' '
136 git symbolic-ref HEAD refs/heads/third &&
140 git checkout other &&
144 cat > expect-third
<<'EOF'
145 commit work7 work7~1 work7^2
146 Merge branch 'third' into other
147 commit work7^2 work7~4
149 commit work7~1 work7~2 work7~1^2
150 Merge branch 'side' into other
151 commit work7~1^2 work7~3
153 commit work7~2 work7~3
155 commit work7~3 work7~4
157 commit work7~4 work7~5
163 test_expect_success
'rebase -i -p with two roots' '
164 git checkout -b work7 other &&
165 git rebase -i -p --root --onto master &&
166 log_with_names work7 > rebased7 &&
167 test_cmp expect-third rebased7
170 test_expect_success
'setup pre-rebase hook that fails' '
171 mkdir -p .git/hooks &&
172 cat >.git/hooks/pre-rebase <<EOF &&
176 chmod +x .git/hooks/pre-rebase
179 test_expect_success
'pre-rebase hook stops rebase' '
180 git checkout -b stops1 other &&
181 test_must_fail git rebase --root --onto master &&
182 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 &&
183 test 0 = $(git rev-list other...stops1 | wc -l)
186 test_expect_success
'pre-rebase hook stops rebase -i' '
187 git checkout -b stops2 other &&
188 test_must_fail git rebase --root --onto master &&
189 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 &&
190 test 0 = $(git rev-list other...stops2 | wc -l)
193 test_expect_success
'remove pre-rebase hook' '
194 rm -f .git/hooks/pre-rebase
197 test_expect_success
'set up a conflict' '
198 git checkout master &&
201 git commit -m conflict
204 test_expect_success
'rebase --root with conflict (first part)' '
205 git checkout -b conflict1 other &&
206 test_must_fail git rebase --root --onto master &&
207 git ls-files -u | grep "B$"
210 test_expect_success
'fix the conflict' '
215 cat > expect-conflict
<<EOF
225 test_expect_success
'rebase --root with conflict (second part)' '
226 git rebase --continue &&
227 git log --pretty=tformat:"%s" > conflict1 &&
228 test_cmp expect-conflict conflict1
231 test_expect_success
'rebase -i --root with conflict (first part)' '
232 git checkout -b conflict2 other &&
233 test_must_fail git rebase -i --root --onto master &&
234 git ls-files -u | grep "B$"
237 test_expect_success
'fix the conflict' '
242 test_expect_success
'rebase -i --root with conflict (second part)' '
243 git rebase --continue &&
244 git log --pretty=tformat:"%s" > conflict2 &&
245 test_cmp expect-conflict conflict2
248 cat >expect-conflict-p
<<\EOF
249 commit conflict3 conflict3~
1 conflict3^
2
250 Merge branch
'third' into other
251 commit conflict3^
2 conflict3~
4
253 commit conflict3~
1 conflict3~
2 conflict3~
1^
2
254 Merge branch
'side' into other
255 commit conflict3~
1^
2 conflict3~
3
257 commit conflict3~
2 conflict3~
3
259 commit conflict3~
3 conflict3~
4
261 commit conflict3~
4 conflict3~
5
263 commit conflict3~
5 conflict3~
6
269 test_expect_success
'rebase -i -p --root with conflict (first part)' '
270 git checkout -b conflict3 other &&
271 test_must_fail git rebase -i -p --root --onto master &&
272 git ls-files -u | grep "B$"
275 test_expect_success
'fix the conflict' '
280 test_expect_success
'rebase -i -p --root with conflict (second part)' '
281 git rebase --continue &&
282 log_with_names conflict3 >out &&
283 test_cmp expect-conflict-p out