dd919100d6848d82833a52fdb9456dcde1c44fbb
1 #!/bin/sh
3 test_description='git rebase --root
5 Tests if git rebase --root --onto <newparent> can rebase the root commit.
6 '
7 . ./test-lib.sh
9 test_expect_success 'prepare repository' '
10 echo 1 > A &&
11 git add A &&
12 git commit -m 1 &&
13 echo 2 > A &&
14 git add A &&
15 git commit -m 2 &&
16 git symbolic-ref HEAD refs/heads/other &&
17 rm .git/index &&
18 echo 3 > B &&
19 git add B &&
20 git commit -m 3 &&
21 echo 1 > A &&
22 git add A &&
23 git commit -m 1b &&
24 echo 4 > B &&
25 git add B &&
26 git commit -m 4
27 '
29 test_expect_success 'rebase --root expects --onto' '
30 test_must_fail git rebase --root
31 '
33 test_expect_success 'setup pre-rebase hook' '
34 mkdir -p .git/hooks &&
35 cat >.git/hooks/pre-rebase <<EOF &&
36 #!$SHELL_PATH
37 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
38 EOF
39 chmod +x .git/hooks/pre-rebase
40 '
41 cat > expect <<EOF
42 4
43 3
44 2
45 1
46 EOF
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
53 '
55 test_expect_success 'pre-rebase got correct input (1)' '
56 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
57 '
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
64 '
66 test_expect_success 'pre-rebase got correct input (2)' '
67 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
68 '
70 test_expect_success 'setup pre-rebase hook that fails' '
71 mkdir -p .git/hooks &&
72 cat >.git/hooks/pre-rebase <<EOF &&
73 #!$SHELL_PATH
74 false
75 EOF
76 chmod +x .git/hooks/pre-rebase
77 '
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)
84 '
86 test_done