]>
Commit | Line | Data |
---|---|---|
6f6bee3b TR |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010 Thomas Rast | |
4 | # | |
5 | ||
6 | test_description='Test the post-rewrite hook.' | |
7 | . ./test-lib.sh | |
8 | ||
9 | test_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 | ||
20 | mkdir .git/hooks | |
21 | ||
22 | cat >.git/hooks/post-rewrite <<EOF | |
23 | #!/bin/sh | |
24 | echo \$@ > "$TRASH_DIRECTORY"/post-rewrite.args | |
25 | cat > "$TRASH_DIRECTORY"/post-rewrite.data | |
26 | EOF | |
27 | chmod u+x .git/hooks/post-rewrite | |
28 | ||
29 | clear_hook_input () { | |
30 | rm -f post-rewrite.args post-rewrite.data | |
31 | } | |
32 | ||
33 | verify_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 | ||
38 | test_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 | ||
48 | test_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 |
56 | test_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 | ||
71 | test_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 | 80 | cat >expected.data <<-EOF && |
45339f74 | 81 | $(git rev-parse C) $(git rev-parse HEAD^) |
141ff8f9 JH |
82 | $(git rev-parse D) $(git rev-parse HEAD) |
83 | EOF | |
96e19488 TR |
84 | verify_hook_input |
85 | ' | |
86 | ||
ef88ad23 JH |
87 | test_expect_success 'git rebase --skip the last one' ' |
88 | git reset --hard F && | |
89 | clear_hook_input && | |
90 | test_must_fail git rebase --onto D A && | |
91 | git rebase --skip && | |
92 | echo rebase >expected.args && | |
141ff8f9 JH |
93 | cat >expected.data <<-EOF && |
94 | $(git rev-parse E) $(git rev-parse HEAD) | |
45339f74 | 95 | $(git rev-parse F) $(git rev-parse HEAD) |
141ff8f9 | 96 | EOF |
ef88ad23 JH |
97 | verify_hook_input |
98 | ' | |
99 | ||
b079feed TR |
100 | test_expect_success 'git rebase -m' ' |
101 | git reset --hard D && | |
102 | clear_hook_input && | |
103 | test_must_fail git rebase -m --onto A B && | |
104 | echo C > foo && | |
105 | git add foo && | |
106 | git rebase --continue && | |
107 | echo rebase >expected.args && | |
141ff8f9 JH |
108 | cat >expected.data <<-EOF && |
109 | $(git rev-parse C) $(git rev-parse HEAD^) | |
110 | $(git rev-parse D) $(git rev-parse HEAD) | |
111 | EOF | |
b079feed TR |
112 | verify_hook_input |
113 | ' | |
114 | ||
115 | test_expect_success 'git rebase -m --skip' ' | |
116 | git reset --hard D && | |
117 | clear_hook_input && | |
e951e8f6 | 118 | test_must_fail git rebase -m --onto A B && |
b079feed TR |
119 | test_must_fail git rebase --skip && |
120 | echo D > foo && | |
121 | git add foo && | |
122 | git rebase --continue && | |
123 | echo rebase >expected.args && | |
141ff8f9 | 124 | cat >expected.data <<-EOF && |
45339f74 | 125 | $(git rev-parse C) $(git rev-parse HEAD^) |
141ff8f9 JH |
126 | $(git rev-parse D) $(git rev-parse HEAD) |
127 | EOF | |
b079feed TR |
128 | verify_hook_input |
129 | ' | |
130 | ||
54006779 EN |
131 | test_expect_success 'git rebase with implicit use of interactive backend' ' |
132 | git reset --hard D && | |
133 | clear_hook_input && | |
dd605e49 | 134 | test_must_fail git rebase --keep-empty --onto A B && |
54006779 EN |
135 | echo C > foo && |
136 | git add foo && | |
137 | git rebase --continue && | |
138 | echo rebase >expected.args && | |
139 | cat >expected.data <<-EOF && | |
140 | $(git rev-parse C) $(git rev-parse HEAD^) | |
141 | $(git rev-parse D) $(git rev-parse HEAD) | |
142 | EOF | |
143 | verify_hook_input | |
144 | ' | |
145 | ||
146 | test_expect_success 'git rebase --skip with implicit use of interactive backend' ' | |
147 | git reset --hard D && | |
148 | clear_hook_input && | |
dd605e49 | 149 | test_must_fail git rebase --keep-empty --onto A B && |
54006779 EN |
150 | test_must_fail git rebase --skip && |
151 | echo D > foo && | |
152 | git add foo && | |
153 | git rebase --continue && | |
154 | echo rebase >expected.args && | |
155 | cat >expected.data <<-EOF && | |
156 | $(git rev-parse C) $(git rev-parse HEAD^) | |
157 | $(git rev-parse D) $(git rev-parse HEAD) | |
158 | EOF | |
159 | verify_hook_input | |
160 | ' | |
161 | ||
b079feed TR |
162 | . "$TEST_DIRECTORY"/lib-rebase.sh |
163 | ||
164 | set_fake_editor | |
165 | ||
166 | # Helper to work around the lack of one-shot exporting for | |
167 | # test_must_fail (as it is a shell function) | |
168 | test_fail_interactive_rebase () { | |
169 | ( | |
170 | FAKE_LINES="$1" && | |
171 | shift && | |
172 | export FAKE_LINES && | |
173 | test_must_fail git rebase -i "$@" | |
174 | ) | |
175 | } | |
176 | ||
177 | test_expect_success 'git rebase -i (unchanged)' ' | |
178 | git reset --hard D && | |
179 | clear_hook_input && | |
180 | test_fail_interactive_rebase "1 2" --onto A B && | |
181 | echo C > foo && | |
182 | git add foo && | |
183 | git rebase --continue && | |
184 | echo rebase >expected.args && | |
141ff8f9 JH |
185 | cat >expected.data <<-EOF && |
186 | $(git rev-parse C) $(git rev-parse HEAD^) | |
187 | $(git rev-parse D) $(git rev-parse HEAD) | |
188 | EOF | |
b079feed TR |
189 | verify_hook_input |
190 | ' | |
191 | ||
192 | test_expect_success 'git rebase -i (skip)' ' | |
193 | git reset --hard D && | |
194 | clear_hook_input && | |
195 | test_fail_interactive_rebase "2" --onto A B && | |
196 | echo D > foo && | |
197 | git add foo && | |
198 | git rebase --continue && | |
199 | echo rebase >expected.args && | |
141ff8f9 JH |
200 | cat >expected.data <<-EOF && |
201 | $(git rev-parse D) $(git rev-parse HEAD) | |
202 | EOF | |
b079feed TR |
203 | verify_hook_input |
204 | ' | |
205 | ||
206 | test_expect_success 'git rebase -i (squash)' ' | |
207 | git reset --hard D && | |
208 | clear_hook_input && | |
209 | test_fail_interactive_rebase "1 squash 2" --onto A B && | |
210 | echo C > foo && | |
211 | git add foo && | |
212 | git rebase --continue && | |
213 | echo rebase >expected.args && | |
141ff8f9 JH |
214 | cat >expected.data <<-EOF && |
215 | $(git rev-parse C) $(git rev-parse HEAD) | |
216 | $(git rev-parse D) $(git rev-parse HEAD) | |
217 | EOF | |
b079feed TR |
218 | verify_hook_input |
219 | ' | |
220 | ||
221 | test_expect_success 'git rebase -i (fixup without conflict)' ' | |
222 | git reset --hard D && | |
223 | clear_hook_input && | |
224 | FAKE_LINES="1 fixup 2" git rebase -i B && | |
225 | echo rebase >expected.args && | |
141ff8f9 JH |
226 | cat >expected.data <<-EOF && |
227 | $(git rev-parse C) $(git rev-parse HEAD) | |
228 | $(git rev-parse D) $(git rev-parse HEAD) | |
229 | EOF | |
b079feed TR |
230 | verify_hook_input |
231 | ' | |
232 | ||
0acb62f2 TR |
233 | test_expect_success 'git rebase -i (double edit)' ' |
234 | git reset --hard D && | |
235 | clear_hook_input && | |
236 | FAKE_LINES="edit 1 edit 2" git rebase -i B && | |
237 | git rebase --continue && | |
238 | echo something > foo && | |
239 | git add foo && | |
240 | git rebase --continue && | |
241 | echo rebase >expected.args && | |
141ff8f9 JH |
242 | cat >expected.data <<-EOF && |
243 | $(git rev-parse C) $(git rev-parse HEAD^) | |
244 | $(git rev-parse D) $(git rev-parse HEAD) | |
245 | EOF | |
0acb62f2 TR |
246 | verify_hook_input |
247 | ' | |
248 | ||
b12d3e90 | 249 | test_expect_success 'git rebase -i (exec)' ' |
1d968ca6 MM |
250 | git reset --hard D && |
251 | clear_hook_input && | |
252 | FAKE_LINES="edit 1 exec_false 2" git rebase -i B && | |
253 | echo something >bar && | |
254 | git add bar && | |
255 | # Fails because of exec false | |
256 | test_must_fail git rebase --continue && | |
257 | git rebase --continue && | |
258 | echo rebase >expected.args && | |
141ff8f9 JH |
259 | cat >expected.data <<-EOF && |
260 | $(git rev-parse C) $(git rev-parse HEAD^) | |
261 | $(git rev-parse D) $(git rev-parse HEAD) | |
262 | EOF | |
1d968ca6 MM |
263 | verify_hook_input |
264 | ' | |
265 | ||
6f6bee3b | 266 | test_done |