]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3413-rebase-hook.sh
The eighth batch
[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' '
c36c6285
ÆAB
44 test_hook --setup pre-rebase <<-\EOF
45 echo "$1,$2" >.git/PRE-REBASE-INPUT
46 EOF
d70b4a8f
NS
47'
48
49test_expect_success 'pre-rebase hook gets correct input (1)' '
50 git checkout test &&
51 git reset --hard side &&
d1c02d93 52 git rebase main &&
d70b4a8f 53 test "z$(cat git)" = zworld &&
d1c02d93 54 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
d70b4a8f
NS
55
56'
57
58test_expect_success 'pre-rebase hook gets correct input (2)' '
59 git checkout test &&
60 git reset --hard side &&
d1c02d93 61 git rebase main test &&
d70b4a8f 62 test "z$(cat git)" = zworld &&
d1c02d93 63 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
64'
65
66test_expect_success 'pre-rebase hook gets correct input (3)' '
67 git checkout test &&
68 git reset --hard side &&
d1c02d93
JS
69 git checkout main &&
70 git rebase main test &&
d70b4a8f 71 test "z$(cat git)" = zworld &&
d1c02d93 72 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
73'
74
75test_expect_success 'pre-rebase hook gets correct input (4)' '
76 git checkout test &&
77 git reset --hard side &&
d1c02d93 78 EDITOR=true git rebase -i main &&
d70b4a8f 79 test "z$(cat git)" = zworld &&
d1c02d93 80 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
d70b4a8f
NS
81
82'
83
84test_expect_success 'pre-rebase hook gets correct input (5)' '
85 git checkout test &&
86 git reset --hard side &&
d1c02d93 87 EDITOR=true git rebase -i main test &&
d70b4a8f 88 test "z$(cat git)" = zworld &&
d1c02d93 89 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
90'
91
92test_expect_success 'pre-rebase hook gets correct input (6)' '
93 git checkout test &&
94 git reset --hard side &&
d1c02d93
JS
95 git checkout main &&
96 EDITOR=true git rebase -i main test &&
d70b4a8f 97 test "z$(cat git)" = zworld &&
d1c02d93 98 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
d70b4a8f
NS
99'
100
101test_expect_success 'setup pre-rebase hook that fails' '
c36c6285
ÆAB
102 test_hook --setup --clobber pre-rebase <<-\EOF
103 false
104 EOF
d70b4a8f
NS
105'
106
107test_expect_success 'pre-rebase hook stops rebase (1)' '
108 git checkout test &&
109 git reset --hard side &&
d1c02d93 110 test_must_fail git rebase main &&
d70b4a8f 111 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
bf6ab087
PW
112 test 0 = $(git rev-list HEAD...side | wc -l) &&
113 test_must_fail git rebase --quit 2>err &&
114 test_grep "no rebase in progress" err
d70b4a8f
NS
115'
116
117test_expect_success 'pre-rebase hook stops rebase (2)' '
118 git checkout test &&
119 git reset --hard side &&
d1c02d93 120 test_must_fail env EDITOR=: git rebase -i main &&
d70b4a8f
NS
121 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
122 test 0 = $(git rev-list HEAD...side | wc -l)
123'
124
c4427656
NS
125test_expect_success 'rebase --no-verify overrides pre-rebase (1)' '
126 git checkout test &&
127 git reset --hard side &&
d1c02d93 128 git rebase --no-verify main &&
c4427656
NS
129 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
130 test "z$(cat git)" = zworld
131'
132
133test_expect_success 'rebase --no-verify overrides pre-rebase (2)' '
134 git checkout test &&
135 git reset --hard side &&
d1c02d93 136 EDITOR=true git rebase --no-verify -i main &&
c4427656
NS
137 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
138 test "z$(cat git)" = zworld
139'
140
d70b4a8f 141test_done