dd919100d6848d82833a52fdb9456dcde1c44fbb
1#!/bin/sh
2
3test_description='git rebase --root
4
5Tests if git rebase --root --onto <newparent> can rebase the root commit.
6'
7. ./test-lib.sh
8
9test_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'
28
29test_expect_success 'rebase --root expects --onto' '
30 test_must_fail git rebase --root
31'
32
33test_expect_success 'setup pre-rebase hook' '
34 mkdir -p .git/hooks &&
35 cat >.git/hooks/pre-rebase <<EOF &&
36#!$SHELL_PATH
37echo "\$1,\$2" >.git/PRE-REBASE-INPUT
38EOF
39 chmod +x .git/hooks/pre-rebase
40'
41cat > expect <<EOF
424
433
442
451
46EOF
47
48test_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'
54
55test_expect_success 'pre-rebase got correct input (1)' '
56 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,
57'
58
59test_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'
65
66test_expect_success 'pre-rebase got correct input (2)' '
67 test "z$(cat .git/PRE-REBASE-INPUT)" = z--root,work2
68'
69
70test_expect_success 'setup pre-rebase hook that fails' '
71 mkdir -p .git/hooks &&
72 cat >.git/hooks/pre-rebase <<EOF &&
73#!$SHELL_PATH
74false
75EOF
76 chmod +x .git/hooks/pre-rebase
77'
78
79test_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'
85
86test_done