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 'setup pre-rebase hook that fails' '
71 mkdir -p .git/hooks &&
72 cat >.git/hooks/pre-rebase <<EOF &&
76 chmod +x .git/hooks/pre-rebase
79 test_expect_success 'pre-rebase hook stops rebase' '
80 git checkout -b stops1 other &&
81 GIT_EDITOR=: test_must_fail git rebase --root --onto master &&
82 test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1
83 test 0 = $(git rev-list other...stops1 | wc -l)