]>
Commit | Line | Data |
---|---|---|
12ace0b2 KH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com> | |
4 | # | |
5 | ||
6 | # FIXME: Test the various index usages, -i and -o, test reflog, | |
264474f2 | 7 | # signoff |
12ace0b2 | 8 | |
47a528ad | 9 | test_description='git commit' |
12ace0b2 | 10 | . ./test-lib.sh |
1af524eb | 11 | . "$TEST_DIRECTORY/diff-lib.sh" |
12ace0b2 | 12 | |
1af524eb | 13 | author='The Real Author <someguy@his.email.org>' |
12ace0b2 | 14 | |
1af524eb | 15 | test_tick |
b3b298af | 16 | |
1af524eb JN |
17 | test_expect_success 'initial status' ' |
18 | echo bongo bongo >file && | |
19 | git add file && | |
32177ba6 JH |
20 | git status >actual && |
21 | test_i18ngrep "Initial commit" actual | |
22 | ' | |
12ace0b2 | 23 | |
1af524eb JN |
24 | test_expect_success 'fail initial amend' ' |
25 | test_must_fail git commit --amend | |
26 | ' | |
12ace0b2 | 27 | |
1af524eb JN |
28 | test_expect_success 'setup: initial commit' ' |
29 | git commit -m initial | |
30 | ' | |
12ace0b2 | 31 | |
1af524eb | 32 | test_expect_success '-m and -F do not mix' ' |
c65dc351 | 33 | git checkout HEAD file && echo >>file && git add file && |
1af524eb JN |
34 | test_must_fail git commit -m foo -m bar -F file |
35 | ' | |
12ace0b2 | 36 | |
1af524eb | 37 | test_expect_success '-m and -C do not mix' ' |
c65dc351 | 38 | git checkout HEAD file && echo >>file && git add file && |
1af524eb JN |
39 | test_must_fail git commit -C HEAD -m illegal |
40 | ' | |
12ace0b2 | 41 | |
1af524eb JN |
42 | test_expect_success 'paths and -a do not mix' ' |
43 | echo King of the bongo >file && | |
44 | test_must_fail git commit -m foo -a file | |
45 | ' | |
9d87442f | 46 | |
e41fcfe9 | 47 | test_expect_success PERL 'can use paths with --interactive' ' |
587ac8c9 JK |
48 | echo bong-o-bong >file && |
49 | # 2: update, 1:st path, that is all, 7: quit | |
50 | ( echo 2; echo 1; echo; echo 7 ) | | |
e41fcfe9 CI |
51 | git commit -m foo --interactive file && |
52 | git reset --hard HEAD^ | |
587ac8c9 | 53 | ' |
9d87442f | 54 | |
1af524eb JN |
55 | test_expect_success 'using invalid commit with -C' ' |
56 | test_must_fail git commit -C bogus | |
57 | ' | |
12ace0b2 | 58 | |
1af524eb JN |
59 | test_expect_success 'nothing to commit' ' |
60 | test_must_fail git commit -m initial | |
61 | ' | |
12ace0b2 | 62 | |
1af524eb JN |
63 | test_expect_success 'setup: non-initial commit' ' |
64 | echo bongo bongo bongo >file && | |
65 | git commit -m next -a | |
66 | ' | |
12ace0b2 | 67 | |
1af524eb JN |
68 | test_expect_success 'commit message from non-existing file' ' |
69 | echo more bongo: bongo bongo bongo bongo >file && | |
70 | test_must_fail git commit -F gah -a | |
71 | ' | |
12ace0b2 | 72 | |
1af524eb JN |
73 | test_expect_success 'empty commit message' ' |
74 | # Empty except stray tabs and spaces on a few lines. | |
75 | sed -e "s/@//g" >msg <<-\EOF && | |
76 | @ @ | |
77 | @@ | |
78 | @ @ | |
79 | @Signed-off-by: hula@ | |
80 | EOF | |
81 | test_must_fail git commit -F msg -a | |
82 | ' | |
12ace0b2 | 83 | |
010c7dbc JH |
84 | test_expect_success 'template "emptyness" check does not kick in with -F' ' |
85 | git checkout HEAD file && echo >>file && git add file && | |
86 | git commit -t file -F file | |
87 | ' | |
88 | ||
b2eda9bd JH |
89 | test_expect_success 'template "emptyness" check' ' |
90 | git checkout HEAD file && echo >>file && git add file && | |
91 | test_must_fail git commit -t file 2>err && | |
92 | test_i18ngrep "did not edit" err | |
93 | ' | |
94 | ||
1af524eb | 95 | test_expect_success 'setup: commit message from file' ' |
010c7dbc | 96 | git checkout HEAD file && echo >>file && git add file && |
1af524eb JN |
97 | echo this is the commit message, coming from a file >msg && |
98 | git commit -F msg -a | |
99 | ' | |
12ace0b2 | 100 | |
1af524eb JN |
101 | test_expect_success 'amend commit' ' |
102 | cat >editor <<-\EOF && | |
103 | #!/bin/sh | |
104 | sed -e "s/a file/an amend commit/g" < "$1" > "$1-" | |
105 | mv "$1-" "$1" | |
106 | EOF | |
107 | chmod 755 editor && | |
108 | EDITOR=./editor git commit --amend | |
109 | ' | |
12ace0b2 | 110 | |
ea2d4ed3 JK |
111 | test_expect_success 'amend --only ignores staged contents' ' |
112 | cp file file.expect && | |
113 | echo changed >file && | |
114 | git add file && | |
115 | git commit --no-edit --amend --only && | |
116 | git cat-file blob HEAD:file >file.actual && | |
117 | test_cmp file.expect file.actual && | |
118 | git diff --exit-code | |
119 | ' | |
120 | ||
bc821899 JN |
121 | test_expect_success 'set up editor' ' |
122 | cat >editor <<-\EOF && | |
123 | #!/bin/sh | |
124 | sed -e "s/unamended/amended/g" <"$1" >"$1-" | |
125 | mv "$1-" "$1" | |
126 | EOF | |
127 | chmod 755 editor | |
128 | ' | |
129 | ||
130 | test_expect_success 'amend without launching editor' ' | |
131 | echo unamended >expect && | |
132 | git commit --allow-empty -m "unamended" && | |
133 | echo needs more bongo >file && | |
134 | git add file && | |
135 | EDITOR=./editor git commit --no-edit --amend && | |
136 | git diff --exit-code HEAD -- file && | |
137 | git diff-tree -s --format=%s HEAD >msg && | |
138 | test_cmp expect msg | |
139 | ' | |
140 | ||
141 | test_expect_success '--amend --edit' ' | |
142 | echo amended >expect && | |
143 | git commit --allow-empty -m "unamended" && | |
144 | echo bongo again >file && | |
145 | git add file && | |
146 | EDITOR=./editor git commit --edit --amend && | |
147 | git diff-tree -s --format=%s HEAD >msg && | |
148 | test_cmp expect msg | |
149 | ' | |
150 | ||
d9a93575 CW |
151 | test_expect_success '--amend --edit of empty message' ' |
152 | cat >replace <<-\EOF && | |
153 | #!/bin/sh | |
154 | echo "amended" >"$1" | |
155 | EOF | |
156 | chmod 755 replace && | |
157 | git commit --allow-empty --allow-empty-message -m "" && | |
158 | echo more bongo >file && | |
159 | git add file && | |
160 | EDITOR=./replace git commit --edit --amend && | |
161 | git diff-tree -s --format=%s HEAD >msg && | |
162 | ./replace expect && | |
163 | test_cmp expect msg | |
164 | ' | |
165 | ||
bc821899 JN |
166 | test_expect_success '-m --edit' ' |
167 | echo amended >expect && | |
168 | git commit --allow-empty -m buffer && | |
169 | echo bongo bongo >file && | |
170 | git add file && | |
171 | EDITOR=./editor git commit -m unamended --edit && | |
172 | git diff-tree -s --format=%s HEAD >msg && | |
173 | test_cmp expect msg | |
174 | ' | |
175 | ||
1af524eb JN |
176 | test_expect_success '-m and -F do not mix' ' |
177 | echo enough with the bongos >file && | |
178 | test_must_fail git commit -F msg -m amending . | |
179 | ' | |
180 | ||
181 | test_expect_success 'using message from other commit' ' | |
182 | git commit -C HEAD^ . | |
183 | ' | |
12ace0b2 | 184 | |
1af524eb JN |
185 | test_expect_success 'editing message from other commit' ' |
186 | cat >editor <<-\EOF && | |
187 | #!/bin/sh | |
188 | sed -e "s/amend/older/g" < "$1" > "$1-" | |
189 | mv "$1-" "$1" | |
190 | EOF | |
191 | chmod 755 editor && | |
192 | echo hula hula >file && | |
193 | EDITOR=./editor git commit -c HEAD^ -a | |
194 | ' | |
12ace0b2 | 195 | |
1af524eb JN |
196 | test_expect_success 'message from stdin' ' |
197 | echo silly new contents >file && | |
198 | echo commit message from stdin | | |
199 | git commit -F - -a | |
200 | ' | |
12ace0b2 | 201 | |
1af524eb JN |
202 | test_expect_success 'overriding author from command line' ' |
203 | echo gak >file && | |
204 | git commit -m author \ | |
205 | --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 && | |
206 | grep Rubber.Duck output | |
207 | ' | |
12ace0b2 | 208 | |
1af524eb JN |
209 | test_expect_success PERL 'interactive add' ' |
210 | echo 7 | | |
211 | git commit --interactive | | |
212 | grep "What now" | |
213 | ' | |
214 | ||
215 | test_expect_success PERL "commit --interactive doesn't change index if editor aborts" ' | |
216 | echo zoo >file && | |
02a481fc | 217 | test_must_fail git diff --exit-code >diff1 && |
1af524eb JN |
218 | (echo u ; echo "*" ; echo q) | |
219 | ( | |
220 | EDITOR=: && | |
221 | export EDITOR && | |
222 | test_must_fail git commit --interactive | |
223 | ) && | |
02a481fc | 224 | git diff >diff2 && |
1af524eb JN |
225 | compare_diff_patch diff1 diff2 |
226 | ' | |
12ace0b2 | 227 | |
1af524eb JN |
228 | test_expect_success 'editor not invoked if -F is given' ' |
229 | cat >editor <<-\EOF && | |
230 | #!/bin/sh | |
231 | sed -e s/good/bad/g <"$1" >"$1-" | |
232 | mv "$1-" "$1" | |
233 | EOF | |
234 | chmod 755 editor && | |
235 | ||
236 | echo A good commit message. >msg && | |
237 | echo moo >file && | |
238 | ||
239 | EDITOR=./editor git commit -a -F msg && | |
240 | git show -s --pretty=format:%s >subject && | |
241 | grep -q good subject && | |
242 | ||
243 | echo quack >file && | |
244 | echo Another good message. | | |
245 | EDITOR=./editor git commit -a -F - && | |
246 | git show -s --pretty=format:%s >subject && | |
247 | grep -q good subject | |
248 | ' | |
12ace0b2 | 249 | |
db33af0a | 250 | test_expect_success 'partial commit that involves removal (1)' ' |
80bffaf7 JH |
251 | |
252 | git rm --cached file && | |
253 | mv file elif && | |
254 | git add elif && | |
255 | git commit -m "Partial: add elif" elif && | |
256 | git diff-tree --name-status HEAD^ HEAD >current && | |
257 | echo "A elif" >expected && | |
1e368681 | 258 | test_cmp expected current |
80bffaf7 JH |
259 | |
260 | ' | |
261 | ||
db33af0a | 262 | test_expect_success 'partial commit that involves removal (2)' ' |
80bffaf7 JH |
263 | |
264 | git commit -m "Partial: remove file" file && | |
265 | git diff-tree --name-status HEAD^ HEAD >current && | |
266 | echo "D file" >expected && | |
1e368681 | 267 | test_cmp expected current |
80bffaf7 JH |
268 | |
269 | ' | |
270 | ||
db33af0a JH |
271 | test_expect_success 'partial commit that involves removal (3)' ' |
272 | ||
273 | git rm --cached elif && | |
274 | echo elif >elif && | |
275 | git commit -m "Partial: modify elif" elif && | |
276 | git diff-tree --name-status HEAD^ HEAD >current && | |
277 | echo "M elif" >expected && | |
1e368681 | 278 | test_cmp expected current |
db33af0a JH |
279 | |
280 | ' | |
281 | ||
5aa5cd46 JH |
282 | test_expect_success 'amend commit to fix author' ' |
283 | ||
284 | oldtick=$GIT_AUTHOR_DATE && | |
285 | test_tick && | |
286 | git reset --hard && | |
287 | git cat-file -p HEAD | | |
288 | sed -e "s/author.*/author $author $oldtick/" \ | |
289 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
290 | expected && | |
291 | git commit --amend --author="$author" && | |
292 | git cat-file -p HEAD > current && | |
1e368681 | 293 | test_cmp expected current |
5aa5cd46 JH |
294 | |
295 | ' | |
296 | ||
02b47cd7 MV |
297 | test_expect_success 'amend commit to fix date' ' |
298 | ||
299 | test_tick && | |
300 | newtick=$GIT_AUTHOR_DATE && | |
301 | git reset --hard && | |
302 | git cat-file -p HEAD | | |
303 | sed -e "s/author.*/author $author $newtick/" \ | |
304 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
305 | expected && | |
306 | git commit --amend --date="$newtick" && | |
307 | git cat-file -p HEAD > current && | |
308 | test_cmp expected current | |
309 | ||
310 | ' | |
311 | ||
4579bb41 JK |
312 | test_expect_success 'commit complains about bogus date' ' |
313 | test_must_fail git commit --amend --date=10.11.2010 | |
314 | ' | |
315 | ||
5aa5cd46 JH |
316 | test_expect_success 'sign off (1)' ' |
317 | ||
318 | echo 1 >positive && | |
319 | git add positive && | |
320 | git commit -s -m "thank you" && | |
321 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
322 | ( | |
323 | echo thank you | |
324 | echo | |
325 | git var GIT_COMMITTER_IDENT | | |
326 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
327 | ) >expected && | |
82ebb0b6 | 328 | test_cmp expected actual |
5aa5cd46 JH |
329 | |
330 | ' | |
331 | ||
332 | test_expect_success 'sign off (2)' ' | |
333 | ||
334 | echo 2 >positive && | |
335 | git add positive && | |
336 | existing="Signed-off-by: Watch This <watchthis@example.com>" && | |
337 | git commit -s -m "thank you | |
338 | ||
339 | $existing" && | |
340 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
341 | ( | |
342 | echo thank you | |
343 | echo | |
344 | echo $existing | |
345 | git var GIT_COMMITTER_IDENT | | |
346 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
347 | ) >expected && | |
82ebb0b6 | 348 | test_cmp expected actual |
5aa5cd46 JH |
349 | |
350 | ' | |
351 | ||
c1e01b0c DB |
352 | test_expect_success 'signoff gap' ' |
353 | ||
354 | echo 3 >positive && | |
355 | git add positive && | |
356 | alt="Alt-RFC-822-Header: Value" && | |
357 | git commit -s -m "welcome | |
358 | ||
359 | $alt" && | |
360 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
361 | ( | |
362 | echo welcome | |
363 | echo | |
364 | echo $alt | |
365 | git var GIT_COMMITTER_IDENT | | |
366 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
367 | ) >expected && | |
368 | test_cmp expected actual | |
369 | ' | |
370 | ||
371 | test_expect_success 'signoff gap 2' ' | |
372 | ||
373 | echo 4 >positive && | |
374 | git add positive && | |
375 | alt="fixed: 34" && | |
376 | git commit -s -m "welcome | |
377 | ||
378 | We have now | |
379 | $alt" && | |
380 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
381 | ( | |
382 | echo welcome | |
383 | echo | |
384 | echo We have now | |
385 | echo $alt | |
386 | echo | |
387 | git var GIT_COMMITTER_IDENT | | |
388 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
389 | ) >expected && | |
390 | test_cmp expected actual | |
391 | ' | |
392 | ||
5aa5cd46 JH |
393 | test_expect_success 'multiple -m' ' |
394 | ||
395 | >negative && | |
396 | git add negative && | |
397 | git commit -m "one" -m "two" -m "three" && | |
398 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
399 | ( | |
400 | echo one | |
401 | echo | |
402 | echo two | |
403 | echo | |
404 | echo three | |
405 | ) >expected && | |
82ebb0b6 | 406 | test_cmp expected actual |
5aa5cd46 JH |
407 | |
408 | ' | |
409 | ||
d63c2fd1 KH |
410 | test_expect_success 'amend commit to fix author' ' |
411 | ||
412 | oldtick=$GIT_AUTHOR_DATE && | |
413 | test_tick && | |
414 | git reset --hard && | |
415 | git cat-file -p HEAD | | |
416 | sed -e "s/author.*/author $author $oldtick/" \ | |
417 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
418 | expected && | |
419 | git commit --amend --author="$author" && | |
420 | git cat-file -p HEAD > current && | |
1e368681 | 421 | test_cmp expected current |
d63c2fd1 KH |
422 | |
423 | ' | |
1200993a KH |
424 | |
425 | test_expect_success 'git commit <file> with dirty index' ' | |
426 | echo tacocat > elif && | |
427 | echo tehlulz > chz && | |
428 | git add chz && | |
429 | git commit elif -m "tacocat is a palindrome" && | |
430 | git show --stat | grep elif && | |
431 | git diff --cached | grep chz | |
432 | ' | |
433 | ||
13aba1e5 JS |
434 | test_expect_success 'same tree (single parent)' ' |
435 | ||
1af524eb JN |
436 | git reset --hard && |
437 | test_must_fail git commit -m empty | |
13aba1e5 JS |
438 | |
439 | ' | |
440 | ||
36863af1 JH |
441 | test_expect_success 'same tree (single parent) --allow-empty' ' |
442 | ||
443 | git commit --allow-empty -m "forced empty" && | |
444 | git cat-file commit HEAD | grep forced | |
445 | ||
446 | ' | |
447 | ||
13aba1e5 JS |
448 | test_expect_success 'same tree (merge and amend merge)' ' |
449 | ||
450 | git checkout -b side HEAD^ && | |
451 | echo zero >zero && | |
452 | git add zero && | |
453 | git commit -m "add zero" && | |
454 | git checkout master && | |
455 | ||
456 | git merge -s ours side -m "empty ok" && | |
457 | git diff HEAD^ HEAD >actual && | |
458 | : >expected && | |
82ebb0b6 | 459 | test_cmp expected actual && |
13aba1e5 JS |
460 | |
461 | git commit --amend -m "empty really ok" && | |
462 | git diff HEAD^ HEAD >actual && | |
463 | : >expected && | |
82ebb0b6 | 464 | test_cmp expected actual |
13aba1e5 JS |
465 | |
466 | ' | |
467 | ||
1eb1e9ee JH |
468 | test_expect_success 'amend using the message from another commit' ' |
469 | ||
470 | git reset --hard && | |
471 | test_tick && | |
472 | git commit --allow-empty -m "old commit" && | |
473 | old=$(git rev-parse --verify HEAD) && | |
474 | test_tick && | |
475 | git commit --allow-empty -m "new commit" && | |
476 | new=$(git rev-parse --verify HEAD) && | |
477 | test_tick && | |
478 | git commit --allow-empty --amend -C "$old" && | |
479 | git show --pretty="format:%ad %s" "$old" >expected && | |
480 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 481 | test_cmp expected actual |
1eb1e9ee JH |
482 | |
483 | ' | |
484 | ||
8a2f8733 JH |
485 | test_expect_success 'amend using the message from a commit named with tag' ' |
486 | ||
487 | git reset --hard && | |
488 | test_tick && | |
489 | git commit --allow-empty -m "old commit" && | |
490 | old=$(git rev-parse --verify HEAD) && | |
491 | git tag -a -m "tag on old" tagged-old HEAD && | |
492 | test_tick && | |
493 | git commit --allow-empty -m "new commit" && | |
494 | new=$(git rev-parse --verify HEAD) && | |
495 | test_tick && | |
496 | git commit --allow-empty --amend -C tagged-old && | |
497 | git show --pretty="format:%ad %s" "$old" >expected && | |
498 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 499 | test_cmp expected actual |
8a2f8733 JH |
500 | |
501 | ' | |
502 | ||
6360d343 TR |
503 | test_expect_success 'amend can copy notes' ' |
504 | ||
505 | git config notes.rewrite.amend true && | |
506 | git config notes.rewriteRef "refs/notes/*" && | |
507 | test_commit foo && | |
508 | git notes add -m"a note" && | |
509 | test_tick && | |
510 | git commit --amend -m"new foo" && | |
511 | test "$(git notes show)" = "a note" | |
512 | ||
513 | ' | |
514 | ||
4682d852 JH |
515 | test_expect_success 'commit a file whose name is a dash' ' |
516 | git reset --hard && | |
517 | for i in 1 2 3 4 5 | |
518 | do | |
519 | echo $i | |
520 | done >./- && | |
521 | git add ./- && | |
522 | test_tick && | |
523 | git commit -m "add dash" >output </dev/null && | |
524 | test_i18ngrep " changed, 5 insertions" output | |
525 | ' | |
526 | ||
f0c73200 TR |
527 | test_expect_success '--only works on to-be-born branch' ' |
528 | # This test relies on having something in the index, as it | |
529 | # would not otherwise actually prove much. So check this. | |
530 | test -n "$(git ls-files)" && | |
531 | git checkout --orphan orphan && | |
532 | echo foo >newfile && | |
533 | git add newfile && | |
534 | git commit --only newfile -m"--only on unborn branch" && | |
535 | echo newfile >expected && | |
536 | git ls-tree -r --name-only HEAD >actual && | |
537 | test_cmp expected actual | |
538 | ' | |
539 | ||
12ace0b2 | 540 | test_done |