]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5407-post-rewrite-hook.sh
t1407: make hash size independent
[thirdparty/git.git] / t / t5407-post-rewrite-hook.sh
CommitLineData
6f6bee3b
TR
1#!/bin/sh
2#
3# Copyright (c) 2010 Thomas Rast
4#
5
6test_description='Test the post-rewrite hook.'
7. ./test-lib.sh
8
9test_expect_success 'setup' '
10 test_commit A foo A &&
11 test_commit B foo B &&
12 test_commit C foo C &&
ef88ad23
JH
13 test_commit D foo D &&
14 git checkout A^0 &&
15 test_commit E bar E &&
16 test_commit F foo F &&
17 git checkout master
6f6bee3b
TR
18'
19
20mkdir .git/hooks
21
22cat >.git/hooks/post-rewrite <<EOF
23#!/bin/sh
24echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args
25cat > "$TRASH_DIRECTORY"/post-rewrite.data
26EOF
27chmod u+x .git/hooks/post-rewrite
28
29clear_hook_input () {
30 rm -f post-rewrite.args post-rewrite.data
31}
32
33verify_hook_input () {
1fee89ce
FC
34 test_cmp expected.args "$TRASH_DIRECTORY"/post-rewrite.args &&
35 test_cmp expected.data "$TRASH_DIRECTORY"/post-rewrite.data
6f6bee3b
TR
36}
37
38test_expect_success 'git commit --amend' '
39 clear_hook_input &&
40 echo "D new message" > newmsg &&
41 oldsha=$(git rev-parse HEAD^0) &&
42 git commit -Fnewmsg --amend &&
43 echo amend > expected.args &&
44 echo $oldsha $(git rev-parse HEAD^0) > expected.data &&
45 verify_hook_input
46'
47
48test_expect_success 'git commit --amend --no-post-rewrite' '
49 clear_hook_input &&
50 echo "D new message again" > newmsg &&
51 git commit --no-post-rewrite -Fnewmsg --amend &&
52 test ! -f post-rewrite.args &&
53 test ! -f post-rewrite.data
54'
55
96e19488
TR
56test_expect_success 'git rebase' '
57 git reset --hard D &&
58 clear_hook_input &&
59 test_must_fail git rebase --onto A B &&
60 echo C > foo &&
61 git add foo &&
62 git rebase --continue &&
63 echo rebase >expected.args &&
141ff8f9
JH
64 cat >expected.data <<-EOF &&
65 $(git rev-parse C) $(git rev-parse HEAD^)
66 $(git rev-parse D) $(git rev-parse HEAD)
67 EOF
96e19488
TR
68 verify_hook_input
69'
70
71test_expect_success 'git rebase --skip' '
72 git reset --hard D &&
73 clear_hook_input &&
74 test_must_fail git rebase --onto A B &&
75 test_must_fail git rebase --skip &&
76 echo D > foo &&
77 git add foo &&
78 git rebase --continue &&
79 echo rebase >expected.args &&
141ff8f9
JH
80 cat >expected.data <<-EOF &&
81 $(git rev-parse D) $(git rev-parse HEAD)
82 EOF
96e19488
TR
83 verify_hook_input
84'
85
ef88ad23
JH
86test_expect_success 'git rebase --skip the last one' '
87 git reset --hard F &&
88 clear_hook_input &&
89 test_must_fail git rebase --onto D A &&
90 git rebase --skip &&
91 echo rebase >expected.args &&
141ff8f9
JH
92 cat >expected.data <<-EOF &&
93 $(git rev-parse E) $(git rev-parse HEAD)
94 EOF
ef88ad23
JH
95 verify_hook_input
96'
97
b079feed
TR
98test_expect_success 'git rebase -m' '
99 git reset --hard D &&
100 clear_hook_input &&
101 test_must_fail git rebase -m --onto A B &&
102 echo C > foo &&
103 git add foo &&
104 git rebase --continue &&
105 echo rebase >expected.args &&
141ff8f9
JH
106 cat >expected.data <<-EOF &&
107 $(git rev-parse C) $(git rev-parse HEAD^)
108 $(git rev-parse D) $(git rev-parse HEAD)
109 EOF
b079feed
TR
110 verify_hook_input
111'
112
113test_expect_success 'git rebase -m --skip' '
114 git reset --hard D &&
115 clear_hook_input &&
e951e8f6 116 test_must_fail git rebase -m --onto A B &&
b079feed
TR
117 test_must_fail git rebase --skip &&
118 echo D > foo &&
119 git add foo &&
120 git rebase --continue &&
121 echo rebase >expected.args &&
141ff8f9
JH
122 cat >expected.data <<-EOF &&
123 $(git rev-parse D) $(git rev-parse HEAD)
124 EOF
b079feed
TR
125 verify_hook_input
126'
127
128. "$TEST_DIRECTORY"/lib-rebase.sh
129
130set_fake_editor
131
132# Helper to work around the lack of one-shot exporting for
133# test_must_fail (as it is a shell function)
134test_fail_interactive_rebase () {
135 (
136 FAKE_LINES="$1" &&
137 shift &&
138 export FAKE_LINES &&
139 test_must_fail git rebase -i "$@"
140 )
141}
142
143test_expect_success 'git rebase -i (unchanged)' '
144 git reset --hard D &&
145 clear_hook_input &&
146 test_fail_interactive_rebase "1 2" --onto A B &&
147 echo C > foo &&
148 git add foo &&
149 git rebase --continue &&
150 echo rebase >expected.args &&
141ff8f9
JH
151 cat >expected.data <<-EOF &&
152 $(git rev-parse C) $(git rev-parse HEAD^)
153 $(git rev-parse D) $(git rev-parse HEAD)
154 EOF
b079feed
TR
155 verify_hook_input
156'
157
158test_expect_success 'git rebase -i (skip)' '
159 git reset --hard D &&
160 clear_hook_input &&
161 test_fail_interactive_rebase "2" --onto A B &&
162 echo D > foo &&
163 git add foo &&
164 git rebase --continue &&
165 echo rebase >expected.args &&
141ff8f9
JH
166 cat >expected.data <<-EOF &&
167 $(git rev-parse D) $(git rev-parse HEAD)
168 EOF
b079feed
TR
169 verify_hook_input
170'
171
172test_expect_success 'git rebase -i (squash)' '
173 git reset --hard D &&
174 clear_hook_input &&
175 test_fail_interactive_rebase "1 squash 2" --onto A B &&
176 echo C > foo &&
177 git add foo &&
178 git rebase --continue &&
179 echo rebase >expected.args &&
141ff8f9
JH
180 cat >expected.data <<-EOF &&
181 $(git rev-parse C) $(git rev-parse HEAD)
182 $(git rev-parse D) $(git rev-parse HEAD)
183 EOF
b079feed
TR
184 verify_hook_input
185'
186
187test_expect_success 'git rebase -i (fixup without conflict)' '
188 git reset --hard D &&
189 clear_hook_input &&
190 FAKE_LINES="1 fixup 2" git rebase -i B &&
191 echo rebase >expected.args &&
141ff8f9
JH
192 cat >expected.data <<-EOF &&
193 $(git rev-parse C) $(git rev-parse HEAD)
194 $(git rev-parse D) $(git rev-parse HEAD)
195 EOF
b079feed
TR
196 verify_hook_input
197'
198
0acb62f2
TR
199test_expect_success 'git rebase -i (double edit)' '
200 git reset --hard D &&
201 clear_hook_input &&
202 FAKE_LINES="edit 1 edit 2" git rebase -i B &&
203 git rebase --continue &&
204 echo something > foo &&
205 git add foo &&
206 git rebase --continue &&
207 echo rebase >expected.args &&
141ff8f9
JH
208 cat >expected.data <<-EOF &&
209 $(git rev-parse C) $(git rev-parse HEAD^)
210 $(git rev-parse D) $(git rev-parse HEAD)
211 EOF
0acb62f2
TR
212 verify_hook_input
213'
214
b12d3e90 215test_expect_success 'git rebase -i (exec)' '
1d968ca6
MM
216 git reset --hard D &&
217 clear_hook_input &&
218 FAKE_LINES="edit 1 exec_false 2" git rebase -i B &&
219 echo something >bar &&
220 git add bar &&
221 # Fails because of exec false
222 test_must_fail git rebase --continue &&
223 git rebase --continue &&
224 echo rebase >expected.args &&
141ff8f9
JH
225 cat >expected.data <<-EOF &&
226 $(git rev-parse C) $(git rev-parse HEAD^)
227 $(git rev-parse D) $(git rev-parse HEAD)
228 EOF
1d968ca6
MM
229 verify_hook_input
230'
231
6f6bee3b 232test_done