3 test_description
='git rebase with its hook(s)'
7 test_expect_success setup
'
11 git commit -m initial &&
15 git commit -m second &&
16 git checkout -b side HEAD^ &&
21 git checkout master &&
22 git log --pretty=oneline --abbrev-commit --graph --all &&
26 test_expect_success
'rebase' '
28 git reset --hard side &&
30 test "z$(cat git)" = zworld
33 test_expect_success
'rebase -i' '
35 git reset --hard side &&
36 EDITOR=true git rebase -i master &&
37 test "z$(cat git)" = zworld
40 test_expect_success
'setup pre-rebase hook' '
41 mkdir -p .git/hooks &&
42 cat >.git/hooks/pre-rebase <<EOF &&
44 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
46 chmod +x .git/hooks/pre-rebase
49 test_expect_success
'pre-rebase hook gets correct input (1)' '
51 git reset --hard side &&
53 test "z$(cat git)" = zworld &&
54 test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,
58 test_expect_success
'pre-rebase hook gets correct input (2)' '
60 git reset --hard side &&
61 git rebase master test &&
62 test "z$(cat git)" = zworld &&
63 test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test
66 test_expect_success
'pre-rebase hook gets correct input (3)' '
68 git reset --hard side &&
69 git checkout master &&
70 git rebase master test &&
71 test "z$(cat git)" = zworld &&
72 test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test
75 test_expect_success
'pre-rebase hook gets correct input (4)' '
77 git reset --hard side &&
78 EDITOR=true git rebase -i master &&
79 test "z$(cat git)" = zworld &&
80 test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,
84 test_expect_success
'pre-rebase hook gets correct input (5)' '
86 git reset --hard side &&
87 EDITOR=true git rebase -i master test &&
88 test "z$(cat git)" = zworld &&
89 test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test
92 test_expect_success
'pre-rebase hook gets correct input (6)' '
94 git reset --hard side &&
95 git checkout master &&
96 EDITOR=true git rebase -i master test &&
97 test "z$(cat git)" = zworld &&
98 test "z$(cat .git/PRE-REBASE-INPUT)" = zmaster,test
101 test_expect_success
'setup pre-rebase hook that fails' '
102 mkdir -p .git/hooks &&
103 cat >.git/hooks/pre-rebase <<EOF &&
107 chmod +x .git/hooks/pre-rebase
110 test_expect_success
'pre-rebase hook stops rebase (1)' '
112 git reset --hard side &&
113 test_must_fail git rebase master &&
114 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
115 test 0 = $(git rev-list HEAD...side | wc -l)
118 test_expect_success
'pre-rebase hook stops rebase (2)' '
120 git reset --hard side &&
121 EDITOR=true test_must_fail git rebase -i master &&
122 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
123 test 0 = $(git rev-list HEAD...side | wc -l)
126 test_expect_success
'rebase --no-verify overrides pre-rebase (1)' '
128 git reset --hard side &&
129 git rebase --no-verify master &&
130 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
131 test "z$(cat git)" = zworld
134 test_expect_success
'rebase --no-verify overrides pre-rebase (2)' '
136 git reset --hard side &&
137 EDITOR=true git rebase --no-verify -i master &&
138 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
139 test "z$(cat git)" = zworld