3 test_description='git rebase --root
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
9 # we always run the interactive rebases unchanged, so just disable the editor
13 test_expect_success 'prepare repository' '
16 git symbolic-ref HEAD refs/heads/other &&
23 test_expect_success 'rebase --root expects --onto' '
24 test_must_fail git rebase --root
27 test_expect_success 'setup pre-rebase hook' '
28 mkdir -p .git/hooks &&
29 cat >.git/hooks/pre-rebase <<EOF &&
31 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
33 chmod +x .git/hooks/pre-rebase
42 test_expect_success 'rebase --root --onto <newbase>' '
43 git checkout -b work &&
44 git rebase --root --onto master &&
45 git log --pretty=tformat:"%s" > rebased &&
46 test_cmp expect rebased
49 test_expect_success 'pre-rebase got correct input (1)' '
50 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
53 test_expect_success 'rebase --root --onto <newbase> <branch>' '
54 git branch work2 other &&
55 git rebase --root --onto master work2 &&
56 git log --pretty=tformat:"%s" > rebased2 &&
57 test_cmp expect rebased2
60 test_expect_success 'pre-rebase got correct input (2)' '
61 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
64 test_expect_success 'rebase -i --root --onto <newbase>' '
65 git checkout -b work3 other &&
66 git rebase -i --root --onto master &&
67 git log --pretty=tformat:"%s" > rebased3 &&
68 test_cmp expect rebased3
71 test_expect_success 'pre-rebase got correct input (3)' '
72 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
75 test_expect_success 'rebase -i --root --onto <newbase> <branch>' '
76 git branch work4 other &&
77 git rebase -i --root --onto master work4 &&
78 git log --pretty=tformat:"%s" > rebased4 &&
79 test_cmp expect rebased4
82 test_expect_success 'pre-rebase got correct input (4)' '
83 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work4
86 test_expect_success 'rebase -i -p with linear history' '
87 git checkout -b work5 other &&
88 git rebase -i -p --root --onto master &&
89 git log --pretty=tformat:"%s" > rebased5 &&
90 test_cmp expect rebased5
93 test_expect_success 'pre-rebase got correct input (5)' '
94 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
97 test_expect_success 'set up merge history' '
98 git checkout other^ &&
99 git checkout -b side &&
101 git checkout other &&
105 sed 's/#/ /g' > expect-side <<'EOF'
106 * Merge branch 'side' into other
116 test_expect_success 'rebase -i -p with merge' '
117 git checkout -b work6 other &&
118 git rebase -i -p --root --onto master &&
119 git log --graph --topo-order --pretty=tformat:"%s" > rebased6 &&
120 test_cmp expect-side rebased6
123 test_expect_success 'set up second root and merge' '
124 git symbolic-ref HEAD refs/heads/third &&
128 git checkout other &&
132 sed 's/#/ /g' > expect-third <<'EOF'
133 * Merge branch 'third' into other
136 * | Merge branch 'side' into other
147 test_expect_success 'rebase -i -p with two roots' '
148 git checkout -b work7 other &&
149 git rebase -i -p --root --onto master &&
150 git log --graph --topo-order --pretty=tformat:"%s" > rebased7 &&
151 test_cmp expect-third rebased7
154 test_expect_success 'setup pre-rebase hook that fails' '
155 mkdir -p .git/hooks &&
156 cat >.git/hooks/pre-rebase <<EOF &&
160 chmod +x .git/hooks/pre-rebase
163 test_expect_success 'pre-rebase hook stops rebase' '
164 git checkout -b stops1 other &&
165 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 &&
172 test_must_fail git rebase --root --onto master &&
173 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2
174 test 0 = $(git rev-list other...stops2 | wc -l)
177 test_expect_success 'remove pre-rebase hook' '
178 rm -f .git/hooks/pre-rebase
181 test_expect_success 'set up a conflict' '
182 git checkout master &&
185 git commit -m conflict
188 test_expect_success 'rebase --root with conflict (first part)' '
189 git checkout -b conflict1 other &&
190 test_must_fail git rebase --root --onto master &&
191 git ls-files -u | grep "B$"
194 test_expect_success 'fix the conflict' '
199 cat > expect-conflict <<EOF
209 test_expect_success 'rebase --root with conflict (second part)' '
210 git rebase --continue &&
211 git log --pretty=tformat:"%s" > conflict1 &&
212 test_cmp expect-conflict conflict1
215 test_expect_success 'rebase -i --root with conflict (first part)' '
216 git checkout -b conflict2 other &&
217 test_must_fail git rebase -i --root --onto master &&
218 git ls-files -u | grep "B$"
221 test_expect_success 'fix the conflict' '
226 test_expect_success 'rebase -i --root with conflict (second part)' '
227 git rebase --continue &&
228 git log --pretty=tformat:"%s" > conflict2 &&
229 test_cmp expect-conflict conflict2
232 cat >expect-conflict-p <<\EOF
233 commit conflict3 conflict3~1 conflict3^2
234 Merge branch 'third' into other
235 commit conflict3^2 conflict3~4
237 commit conflict3~1 conflict3~2 conflict3~1^2
238 Merge branch 'side' into other
239 commit conflict3~1^2 conflict3~3
241 commit conflict3~2 conflict3~3
243 commit conflict3~3 conflict3~4
245 commit conflict3~4 conflict3~5
247 commit conflict3~5 conflict3~6
253 test_expect_success 'rebase -i -p --root with conflict (first part)' '
254 git checkout -b conflict3 other &&
255 test_must_fail git rebase -i -p --root --onto master &&
256 git ls-files -u | grep "B$"
259 test_expect_success 'fix the conflict' '
264 test_expect_success 'rebase -i -p --root with conflict (second part)' '
265 git rebase --continue &&
266 git rev-list --topo-order --parents --pretty="tformat:%s" HEAD |
267 git name-rev --stdin --name-only --refs=refs/heads/conflict3 >out &&
268 test_cmp expect-conflict-p out