cocci: apply "pending" index-compatibility to "t/helper/*.c"
[git/debian.git] / t / t5407-post-rewrite-hook.sh
blob5f3ff051ca2fa3bba8beabbcb1491d5e69262f34
1 #!/bin/sh
3 # Copyright (c) 2010 Thomas Rast
6 test_description='Test the post-rewrite hook.'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 . ./test-lib.sh
12 test_expect_success 'setup' '
13 test_commit A foo A &&
14 test_commit B foo B &&
15 test_commit C foo C &&
16 test_commit D foo D &&
17 git checkout A^0 &&
18 test_commit E bar E &&
19 test_commit F foo F &&
20 git checkout main &&
22 test_hook --setup post-rewrite <<-EOF
23 echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
24 cat > "$TRASH_DIRECTORY"/post-rewrite.data
25 EOF
28 clear_hook_input () {
29 rm -f post-rewrite.args post-rewrite.data
32 verify_hook_input () {
33 test_cmp expected.args "$TRASH_DIRECTORY"/post-rewrite.args &&
34 test_cmp expected.data "$TRASH_DIRECTORY"/post-rewrite.data
37 test_expect_success 'git commit --amend' '
38 clear_hook_input &&
39 echo "D new message" > newmsg &&
40 oldsha=$(git rev-parse HEAD^0) &&
41 git commit -Fnewmsg --amend &&
42 echo amend > expected.args &&
43 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
44 verify_hook_input
47 test_expect_success 'git commit --amend --no-post-rewrite' '
48 clear_hook_input &&
49 echo "D new message again" > newmsg &&
50 git commit --no-post-rewrite -Fnewmsg --amend &&
51 test ! -f post-rewrite.args &&
52 test ! -f post-rewrite.data
55 test_expect_success 'git rebase --apply' '
56 git reset --hard D &&
57 clear_hook_input &&
58 test_must_fail git rebase --apply --onto A B &&
59 echo C > foo &&
60 git add foo &&
61 git rebase --continue &&
62 echo rebase >expected.args &&
63 cat >expected.data <<-EOF &&
64 $(git rev-parse C) $(git rev-parse HEAD^)
65 $(git rev-parse D) $(git rev-parse HEAD)
66 EOF
67 verify_hook_input
70 test_expect_success 'git rebase --apply --skip' '
71 git reset --hard D &&
72 clear_hook_input &&
73 test_must_fail git rebase --apply --onto A B &&
74 test_must_fail git rebase --skip &&
75 echo D > foo &&
76 git add foo &&
77 git rebase --continue &&
78 echo rebase >expected.args &&
79 cat >expected.data <<-EOF &&
80 $(git rev-parse C) $(git rev-parse HEAD^)
81 $(git rev-parse D) $(git rev-parse HEAD)
82 EOF
83 verify_hook_input
86 test_expect_success 'git rebase --apply --skip the last one' '
87 git reset --hard F &&
88 clear_hook_input &&
89 test_must_fail git rebase --apply --onto D A &&
90 git rebase --skip &&
91 echo rebase >expected.args &&
92 cat >expected.data <<-EOF &&
93 $(git rev-parse E) $(git rev-parse HEAD)
94 $(git rev-parse F) $(git rev-parse HEAD)
95 EOF
96 verify_hook_input
99 test_expect_success 'git rebase -m' '
100 git reset --hard D &&
101 clear_hook_input &&
102 test_must_fail git rebase -m --onto A B &&
103 echo C > foo &&
104 git add foo &&
105 git rebase --continue &&
106 echo rebase >expected.args &&
107 cat >expected.data <<-EOF &&
108 $(git rev-parse C) $(git rev-parse HEAD^)
109 $(git rev-parse D) $(git rev-parse HEAD)
111 verify_hook_input
114 test_expect_success 'git rebase -m --skip' '
115 git reset --hard D &&
116 clear_hook_input &&
117 test_must_fail git rebase -m --onto A B &&
118 test_must_fail git rebase --skip &&
119 echo D > foo &&
120 git add foo &&
121 git rebase --continue &&
122 echo rebase >expected.args &&
123 cat >expected.data <<-EOF &&
124 $(git rev-parse C) $(git rev-parse HEAD^)
125 $(git rev-parse D) $(git rev-parse HEAD)
127 verify_hook_input
130 test_expect_success 'git rebase with implicit use of merge backend' '
131 git reset --hard D &&
132 clear_hook_input &&
133 test_must_fail git rebase --keep-empty --onto A B &&
134 echo C > foo &&
135 git add foo &&
136 git rebase --continue &&
137 echo rebase >expected.args &&
138 cat >expected.data <<-EOF &&
139 $(git rev-parse C) $(git rev-parse HEAD^)
140 $(git rev-parse D) $(git rev-parse HEAD)
142 verify_hook_input
145 test_expect_success 'git rebase --skip with implicit use of merge backend' '
146 git reset --hard D &&
147 clear_hook_input &&
148 test_must_fail git rebase --keep-empty --onto A B &&
149 test_must_fail git rebase --skip &&
150 echo D > foo &&
151 git add foo &&
152 git rebase --continue &&
153 echo rebase >expected.args &&
154 cat >expected.data <<-EOF &&
155 $(git rev-parse C) $(git rev-parse HEAD^)
156 $(git rev-parse D) $(git rev-parse HEAD)
158 verify_hook_input
161 . "$TEST_DIRECTORY"/lib-rebase.sh
163 set_fake_editor
165 # Helper to work around the lack of one-shot exporting for
166 # test_must_fail (as it is a shell function)
167 test_fail_interactive_rebase () {
169 FAKE_LINES="$1" &&
170 shift &&
171 export FAKE_LINES &&
172 test_must_fail git rebase -i "$@"
176 test_expect_success 'git rebase -i (unchanged)' '
177 git reset --hard D &&
178 clear_hook_input &&
179 test_fail_interactive_rebase "1 2" --onto A B &&
180 echo C > foo &&
181 git add foo &&
182 git rebase --continue &&
183 echo rebase >expected.args &&
184 cat >expected.data <<-EOF &&
185 $(git rev-parse C) $(git rev-parse HEAD^)
186 $(git rev-parse D) $(git rev-parse HEAD)
188 verify_hook_input
191 test_expect_success 'git rebase -i (skip)' '
192 git reset --hard D &&
193 clear_hook_input &&
194 test_fail_interactive_rebase "2" --onto A B &&
195 echo D > foo &&
196 git add foo &&
197 git rebase --continue &&
198 echo rebase >expected.args &&
199 cat >expected.data <<-EOF &&
200 $(git rev-parse D) $(git rev-parse HEAD)
202 verify_hook_input
205 test_expect_success 'git rebase -i (squash)' '
206 git reset --hard D &&
207 clear_hook_input &&
208 test_fail_interactive_rebase "1 squash 2" --onto A B &&
209 echo C > foo &&
210 git add foo &&
211 git rebase --continue &&
212 echo rebase >expected.args &&
213 cat >expected.data <<-EOF &&
214 $(git rev-parse C) $(git rev-parse HEAD)
215 $(git rev-parse D) $(git rev-parse HEAD)
217 verify_hook_input
220 test_expect_success 'git rebase -i (fixup without conflict)' '
221 git reset --hard D &&
222 clear_hook_input &&
223 FAKE_LINES="1 fixup 2" git rebase -i B &&
224 echo rebase >expected.args &&
225 cat >expected.data <<-EOF &&
226 $(git rev-parse C) $(git rev-parse HEAD)
227 $(git rev-parse D) $(git rev-parse HEAD)
229 verify_hook_input
232 test_expect_success 'git rebase -i (double edit)' '
233 git reset --hard D &&
234 clear_hook_input &&
235 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
236 git rebase --continue &&
237 echo something > foo &&
238 git add foo &&
239 git rebase --continue &&
240 echo rebase >expected.args &&
241 cat >expected.data <<-EOF &&
242 $(git rev-parse C) $(git rev-parse HEAD^)
243 $(git rev-parse D) $(git rev-parse HEAD)
245 verify_hook_input
248 test_expect_success 'git rebase -i (exec)' '
249 git reset --hard D &&
250 clear_hook_input &&
251 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
252 echo something >bar &&
253 git add bar &&
254 # Fails because of exec false
255 test_must_fail git rebase --continue &&
256 git rebase --continue &&
257 echo rebase >expected.args &&
258 cat >expected.data <<-EOF &&
259 $(git rev-parse C) $(git rev-parse HEAD^)
260 $(git rev-parse D) $(git rev-parse HEAD)
262 verify_hook_input
265 test_done