]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3413-rebase-hook.sh
Merge branch 'gc/branch-recurse-submodules-fix'
[thirdparty/git.git] / t / t3413-rebase-hook.sh
1 #!/bin/sh
2
3 test_description='git rebase with its hook(s)'
4
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9
10 test_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 &&
24 git checkout main &&
25 git log --pretty=oneline --abbrev-commit --graph --all &&
26 git branch test side
27 '
28
29 test_expect_success 'rebase' '
30 git checkout test &&
31 git reset --hard side &&
32 git rebase main &&
33 test "z$(cat git)" = zworld
34 '
35
36 test_expect_success 'rebase -i' '
37 git checkout test &&
38 git reset --hard side &&
39 EDITOR=true git rebase -i main &&
40 test "z$(cat git)" = zworld
41 '
42
43 test_expect_success 'setup pre-rebase hook' '
44 test_hook --setup pre-rebase <<-\EOF
45 echo "$1,$2" >.git/PRE-REBASE-INPUT
46 EOF
47 '
48
49 test_expect_success 'pre-rebase hook gets correct input (1)' '
50 git checkout test &&
51 git reset --hard side &&
52 git rebase main &&
53 test "z$(cat git)" = zworld &&
54 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
55
56 '
57
58 test_expect_success 'pre-rebase hook gets correct input (2)' '
59 git checkout test &&
60 git reset --hard side &&
61 git rebase main test &&
62 test "z$(cat git)" = zworld &&
63 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
64 '
65
66 test_expect_success 'pre-rebase hook gets correct input (3)' '
67 git checkout test &&
68 git reset --hard side &&
69 git checkout main &&
70 git rebase main test &&
71 test "z$(cat git)" = zworld &&
72 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
73 '
74
75 test_expect_success 'pre-rebase hook gets correct input (4)' '
76 git checkout test &&
77 git reset --hard side &&
78 EDITOR=true git rebase -i main &&
79 test "z$(cat git)" = zworld &&
80 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,
81
82 '
83
84 test_expect_success 'pre-rebase hook gets correct input (5)' '
85 git checkout test &&
86 git reset --hard side &&
87 EDITOR=true git rebase -i main test &&
88 test "z$(cat git)" = zworld &&
89 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
90 '
91
92 test_expect_success 'pre-rebase hook gets correct input (6)' '
93 git checkout test &&
94 git reset --hard side &&
95 git checkout main &&
96 EDITOR=true git rebase -i main test &&
97 test "z$(cat git)" = zworld &&
98 test "z$(cat .git/PRE-REBASE-INPUT)" = zmain,test
99 '
100
101 test_expect_success 'setup pre-rebase hook that fails' '
102 test_hook --setup --clobber pre-rebase <<-\EOF
103 false
104 EOF
105 '
106
107 test_expect_success 'pre-rebase hook stops rebase (1)' '
108 git checkout test &&
109 git reset --hard side &&
110 test_must_fail git rebase main &&
111 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
112 test 0 = $(git rev-list HEAD...side | wc -l)
113 '
114
115 test_expect_success 'pre-rebase hook stops rebase (2)' '
116 git checkout test &&
117 git reset --hard side &&
118 test_must_fail env EDITOR=: git rebase -i main &&
119 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
120 test 0 = $(git rev-list HEAD...side | wc -l)
121 '
122
123 test_expect_success 'rebase --no-verify overrides pre-rebase (1)' '
124 git checkout test &&
125 git reset --hard side &&
126 git rebase --no-verify main &&
127 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
128 test "z$(cat git)" = zworld
129 '
130
131 test_expect_success 'rebase --no-verify overrides pre-rebase (2)' '
132 git checkout test &&
133 git reset --hard side &&
134 EDITOR=true git rebase --no-verify -i main &&
135 test "z$(git symbolic-ref HEAD)" = zrefs/heads/test &&
136 test "z$(cat git)" = zworld
137 '
138
139 test_done