3 test_description='git rebase with its hook(s)'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success setup '
14 git commit -m initial &&
18 git commit -m second &&
19 git checkout -b side HEAD^ &&
25 git log --pretty=oneline --abbrev-commit --graph --all &&
29 test_expect_success 'rebase' '
31 git reset --hard side &&
33 test "z$(cat git)" = zworld
36 test_expect_success 'rebase -i' '
38 git reset --hard side &&
39 EDITOR=true git rebase -i main &&
40 test "z$(cat git)" = zworld
43 test_expect_success 'setup pre-rebase hook' '
44 mkdir -p .git/hooks &&
45 cat >.git/hooks/pre-rebase <<EOF &&
47 echo "\$1,\$2" >.git/PRE-REBASE-INPUT
49 chmod +x .git/hooks/pre-rebase
52 test_expect_success 'pre-rebase hook gets correct input (1)' '
54 git reset --hard side &&
56 test "z$(cat git)" = zworld &&
57 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
61 test_expect_success 'pre-rebase hook gets correct input (2)' '
63 git reset --hard side &&
64 git rebase main test &&
65 test "z$(cat git)" = zworld &&
66 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
69 test_expect_success 'pre-rebase hook gets correct input (3)' '
71 git reset --hard side &&
73 git rebase main test &&
74 test "z$(cat git)" = zworld &&
75 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
78 test_expect_success 'pre-rebase hook gets correct input (4)' '
80 git reset --hard side &&
81 EDITOR=true git rebase -i main &&
82 test "z$(cat git)" = zworld &&
83 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
87 test_expect_success 'pre-rebase hook gets correct input (5)' '
89 git reset --hard side &&
90 EDITOR=true git rebase -i main test &&
91 test "z$(cat git)" = zworld &&
92 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
95 test_expect_success 'pre-rebase hook gets correct input (6)' '
97 git reset --hard side &&
99 EDITOR=true git rebase -i main test &&
100 test "z$(cat git)" = zworld &&
101 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
104 test_expect_success 'setup pre-rebase hook that fails' '
105 mkdir -p .git/hooks &&
106 cat >.git/hooks/pre-rebase <<EOF &&
110 chmod +x .git/hooks/pre-rebase
113 test_expect_success 'pre-rebase hook stops rebase (1)' '
115 git reset --hard side &&
116 test_must_fail git rebase main &&
117 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
118 test 0 = $(git rev-list HEAD...side | wc -l)
121 test_expect_success 'pre-rebase hook stops rebase (2)' '
123 git reset --hard side &&
124 test_must_fail env EDITOR=: git rebase -i main &&
125 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
126 test 0 = $(git rev-list HEAD...side | wc -l)
129 test_expect_success 'rebase --no-verify overrides pre-rebase (1)' '
131 git reset --hard side &&
132 git rebase --no-verify main &&
133 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
134 test "z$(cat git)" = zworld
137 test_expect_success 'rebase --no-verify overrides pre-rebase (2)' '
139 git reset --hard side &&
140 EDITOR=true git rebase --no-verify -i main &&
141 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
142 test "z$(cat git)" = zworld