]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3413-rebase-hook.sh
t550*: adjust the references to the default branch name "main"
[thirdparty/git.git] / t / t3413-rebase-hook.sh
CommitLineData
d70b4a8f
NS
1#!/bin/sh
2
3test_description='git rebase with its hook(s)'
4
d1c02d93 5GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
6export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
d70b4a8f
NS
8. ./test-lib.sh
9
10test_expect_success setup '
11 echo hello >file &&
12 git add file &&
13 test_tick &&
14 git commit -m initial &&
15 echo goodbye >file &&
16 git add file &&
17 test_tick &&
18 git commit -m second &&
19 git checkout -b side HEAD^ &&
20 echo world >git &&
21 git add git &&
22 test_tick &&
23 git commit -m side &&
d1c02d93 24 git checkout main &&
d70b4a8f
NS
25 git log --pretty=oneline --abbrev-commit --graph --all &&
26 git branch test side
27'
28
29test_expect_success 'rebase' '
30 git checkout test &&
31 git reset --hard side &&
d1c02d93 32 git rebase main &&
d70b4a8f
NS
33 test "z$(cat git)" = zworld
34'
35
36test_expect_success 'rebase -i' '
37 git checkout test &&
38 git reset --hard side &&
d1c02d93 39 EDITOR=true git rebase -i main &&
d70b4a8f
NS
40 test "z$(cat git)" = zworld
41'
42
43test_expect_success 'setup pre-rebase hook' '
44 mkdir -p .git/hooks &&
45 cat >.git/hooks/pre-rebase <<EOF &&
46#!$SHELL_PATH
47echo "\$1,\$2" >.git/PRE-REBASE-INPUT
48EOF
49 chmod +x .git/hooks/pre-rebase
50'
51
52test_expect_success 'pre-rebase hook gets correct input (1)' '
53 git checkout test &&
54 git reset --hard side &&
d1c02d93 55 git rebase main &&
d70b4a8f 56 test "z$(cat git)" = zworld &&
d1c02d93 57 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
d70b4a8f
NS
58
59'
60
61test_expect_success 'pre-rebase hook gets correct input (2)' '
62 git checkout test &&
63 git reset --hard side &&
d1c02d93 64 git rebase main test &&
d70b4a8f 65 test "z$(cat git)" = zworld &&
d1c02d93 66 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
67'
68
69test_expect_success 'pre-rebase hook gets correct input (3)' '
70 git checkout test &&
71 git reset --hard side &&
d1c02d93
JS
72 git checkout main &&
73 git rebase main test &&
d70b4a8f 74 test "z$(cat git)" = zworld &&
d1c02d93 75 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
76'
77
78test_expect_success 'pre-rebase hook gets correct input (4)' '
79 git checkout test &&
80 git reset --hard side &&
d1c02d93 81 EDITOR=true git rebase -i main &&
d70b4a8f 82 test "z$(cat git)" = zworld &&
d1c02d93 83 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
d70b4a8f
NS
84
85'
86
87test_expect_success 'pre-rebase hook gets correct input (5)' '
88 git checkout test &&
89 git reset --hard side &&
d1c02d93 90 EDITOR=true git rebase -i main test &&
d70b4a8f 91 test "z$(cat git)" = zworld &&
d1c02d93 92 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
93'
94
95test_expect_success 'pre-rebase hook gets correct input (6)' '
96 git checkout test &&
97 git reset --hard side &&
d1c02d93
JS
98 git checkout main &&
99 EDITOR=true git rebase -i main test &&
d70b4a8f 100 test "z$(cat git)" = zworld &&
d1c02d93 101 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
102'
103
104test_expect_success 'setup pre-rebase hook that fails' '
105 mkdir -p .git/hooks &&
106 cat >.git/hooks/pre-rebase <<EOF &&
107#!$SHELL_PATH
108false
109EOF
110 chmod +x .git/hooks/pre-rebase
111'
112
113test_expect_success 'pre-rebase hook stops rebase (1)' '
114 git checkout test &&
115 git reset --hard side &&
d1c02d93 116 test_must_fail git rebase main &&
d70b4a8f
NS
117 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
118 test 0 = $(git rev-list HEAD...side | wc -l)
119'
120
121test_expect_success 'pre-rebase hook stops rebase (2)' '
122 git checkout test &&
123 git reset --hard side &&
d1c02d93 124 test_must_fail env EDITOR=: git rebase -i main &&
d70b4a8f
NS
125 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
126 test 0 = $(git rev-list HEAD...side | wc -l)
127'
128
c4427656
NS
129test_expect_success 'rebase --no-verify overrides pre-rebase (1)' '
130 git checkout test &&
131 git reset --hard side &&
d1c02d93 132 git rebase --no-verify main &&
c4427656
NS
133 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
134 test "z$(cat git)" = zworld
135'
136
137test_expect_success 'rebase --no-verify overrides pre-rebase (2)' '
138 git checkout test &&
139 git reset --hard side &&
d1c02d93 140 EDITOR=true git rebase --no-verify -i main &&
c4427656
NS
141 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
142 test "z$(cat git)" = zworld
143'
144
d70b4a8f 145test_done