]>
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 | 20 | git status >actual && |
4ddb1354 | 21 | test_i18ngrep "No commits yet" actual |
32177ba6 | 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 | |
0590ff26 | 50 | test_write_lines 2 1 "" 7 | |
e41fcfe9 CI |
51 | git commit -m foo --interactive file && |
52 | git reset --hard HEAD^ | |
587ac8c9 | 53 | ' |
9d87442f | 54 | |
86238e07 BW |
55 | test_expect_success 'removed files and relative paths' ' |
56 | test_when_finished "rm -rf foo" && | |
57 | git init foo && | |
58 | >foo/foo.txt && | |
59 | git -C foo add foo.txt && | |
60 | git -C foo commit -m first && | |
61 | git -C foo rm foo.txt && | |
62 | ||
63 | mkdir -p foo/bar && | |
64 | git -C foo/bar commit -m second ../foo.txt | |
65 | ' | |
66 | ||
1af524eb | 67 | test_expect_success 'using invalid commit with -C' ' |
0bb0c155 | 68 | test_must_fail git commit --allow-empty -C bogus |
1af524eb | 69 | ' |
12ace0b2 | 70 | |
1af524eb | 71 | test_expect_success 'nothing to commit' ' |
088304bf | 72 | git reset --hard && |
1af524eb JN |
73 | test_must_fail git commit -m initial |
74 | ' | |
12ace0b2 | 75 | |
9cbcc2a7 TRC |
76 | test_expect_success '--dry-run fails with nothing to commit' ' |
77 | test_must_fail git commit -m initial --dry-run | |
78 | ' | |
79 | ||
80 | test_expect_success '--short fails with nothing to commit' ' | |
81 | test_must_fail git commit -m initial --short | |
82 | ' | |
83 | ||
84 | test_expect_success '--porcelain fails with nothing to commit' ' | |
85 | test_must_fail git commit -m initial --porcelain | |
86 | ' | |
87 | ||
88 | test_expect_success '--long fails with nothing to commit' ' | |
89 | test_must_fail git commit -m initial --long | |
90 | ' | |
91 | ||
1af524eb JN |
92 | test_expect_success 'setup: non-initial commit' ' |
93 | echo bongo bongo bongo >file && | |
94 | git commit -m next -a | |
95 | ' | |
12ace0b2 | 96 | |
9cbcc2a7 TRC |
97 | test_expect_success '--dry-run with stuff to commit returns ok' ' |
98 | echo bongo bongo bongo >>file && | |
99 | git commit -m next -a --dry-run | |
100 | ' | |
101 | ||
102 | test_expect_failure '--short with stuff to commit returns ok' ' | |
103 | echo bongo bongo bongo >>file && | |
104 | git commit -m next -a --short | |
105 | ' | |
106 | ||
107 | test_expect_failure '--porcelain with stuff to commit returns ok' ' | |
108 | echo bongo bongo bongo >>file && | |
109 | git commit -m next -a --porcelain | |
110 | ' | |
111 | ||
112 | test_expect_success '--long with stuff to commit returns ok' ' | |
113 | echo bongo bongo bongo >>file && | |
114 | git commit -m next -a --long | |
115 | ' | |
116 | ||
1af524eb JN |
117 | test_expect_success 'commit message from non-existing file' ' |
118 | echo more bongo: bongo bongo bongo bongo >file && | |
119 | test_must_fail git commit -F gah -a | |
120 | ' | |
12ace0b2 | 121 | |
1af524eb JN |
122 | test_expect_success 'empty commit message' ' |
123 | # Empty except stray tabs and spaces on a few lines. | |
124 | sed -e "s/@//g" >msg <<-\EOF && | |
125 | @ @ | |
126 | @@ | |
127 | @ @ | |
128 | @Signed-off-by: hula@ | |
129 | EOF | |
130 | test_must_fail git commit -F msg -a | |
131 | ' | |
12ace0b2 | 132 | |
010c7dbc JH |
133 | test_expect_success 'template "emptyness" check does not kick in with -F' ' |
134 | git checkout HEAD file && echo >>file && git add file && | |
135 | git commit -t file -F file | |
136 | ' | |
137 | ||
b2eda9bd JH |
138 | test_expect_success 'template "emptyness" check' ' |
139 | git checkout HEAD file && echo >>file && git add file && | |
140 | test_must_fail git commit -t file 2>err && | |
141 | test_i18ngrep "did not edit" err | |
142 | ' | |
143 | ||
1af524eb | 144 | test_expect_success 'setup: commit message from file' ' |
010c7dbc | 145 | git checkout HEAD file && echo >>file && git add file && |
1af524eb JN |
146 | echo this is the commit message, coming from a file >msg && |
147 | git commit -F msg -a | |
148 | ' | |
12ace0b2 | 149 | |
1af524eb JN |
150 | test_expect_success 'amend commit' ' |
151 | cat >editor <<-\EOF && | |
152 | #!/bin/sh | |
153 | sed -e "s/a file/an amend commit/g" < "$1" > "$1-" | |
154 | mv "$1-" "$1" | |
155 | EOF | |
156 | chmod 755 editor && | |
157 | EDITOR=./editor git commit --amend | |
158 | ' | |
12ace0b2 | 159 | |
ea2d4ed3 JK |
160 | test_expect_success 'amend --only ignores staged contents' ' |
161 | cp file file.expect && | |
162 | echo changed >file && | |
163 | git add file && | |
164 | git commit --no-edit --amend --only && | |
165 | git cat-file blob HEAD:file >file.actual && | |
166 | test_cmp file.expect file.actual && | |
167 | git diff --exit-code | |
168 | ' | |
169 | ||
319d8352 AK |
170 | test_expect_success 'allow-empty --only ignores staged contents' ' |
171 | echo changed-again >file && | |
172 | git add file && | |
173 | git commit --allow-empty --only -m "empty" && | |
174 | git cat-file blob HEAD:file >file.actual && | |
175 | test_cmp file.expect file.actual && | |
ea2d4ed3 JK |
176 | git diff --exit-code |
177 | ' | |
178 | ||
bc821899 JN |
179 | test_expect_success 'set up editor' ' |
180 | cat >editor <<-\EOF && | |
181 | #!/bin/sh | |
182 | sed -e "s/unamended/amended/g" <"$1" >"$1-" | |
183 | mv "$1-" "$1" | |
184 | EOF | |
185 | chmod 755 editor | |
186 | ' | |
187 | ||
188 | test_expect_success 'amend without launching editor' ' | |
189 | echo unamended >expect && | |
190 | git commit --allow-empty -m "unamended" && | |
191 | echo needs more bongo >file && | |
192 | git add file && | |
193 | EDITOR=./editor git commit --no-edit --amend && | |
194 | git diff --exit-code HEAD -- file && | |
195 | git diff-tree -s --format=%s HEAD >msg && | |
196 | test_cmp expect msg | |
197 | ' | |
198 | ||
199 | test_expect_success '--amend --edit' ' | |
200 | echo amended >expect && | |
201 | git commit --allow-empty -m "unamended" && | |
202 | echo bongo again >file && | |
203 | git add file && | |
204 | EDITOR=./editor git commit --edit --amend && | |
205 | git diff-tree -s --format=%s HEAD >msg && | |
206 | test_cmp expect msg | |
207 | ' | |
208 | ||
d9a93575 CW |
209 | test_expect_success '--amend --edit of empty message' ' |
210 | cat >replace <<-\EOF && | |
211 | #!/bin/sh | |
212 | echo "amended" >"$1" | |
213 | EOF | |
214 | chmod 755 replace && | |
215 | git commit --allow-empty --allow-empty-message -m "" && | |
216 | echo more bongo >file && | |
217 | git add file && | |
218 | EDITOR=./replace git commit --edit --amend && | |
219 | git diff-tree -s --format=%s HEAD >msg && | |
220 | ./replace expect && | |
221 | test_cmp expect msg | |
222 | ' | |
223 | ||
27014cbc JK |
224 | test_expect_success '--amend to set message to empty' ' |
225 | echo bata >file && | |
178e8143 AD |
226 | git add file && |
227 | git commit -m "unamended" && | |
228 | git commit --amend --allow-empty-message -m "" && | |
229 | git diff-tree -s --format=%s HEAD >msg && | |
230 | echo "" >expect && | |
231 | test_cmp expect msg | |
232 | ' | |
233 | ||
27014cbc | 234 | test_expect_success '--amend to set empty message needs --allow-empty-message' ' |
178e8143 AD |
235 | echo conga >file && |
236 | git add file && | |
237 | git commit -m "unamended" && | |
238 | test_must_fail git commit --amend -m "" && | |
239 | git diff-tree -s --format=%s HEAD >msg && | |
240 | echo "unamended" >expect && | |
241 | test_cmp expect msg | |
242 | ' | |
243 | ||
bc821899 JN |
244 | test_expect_success '-m --edit' ' |
245 | echo amended >expect && | |
246 | git commit --allow-empty -m buffer && | |
247 | echo bongo bongo >file && | |
248 | git add file && | |
249 | EDITOR=./editor git commit -m unamended --edit && | |
250 | git diff-tree -s --format=%s HEAD >msg && | |
251 | test_cmp expect msg | |
252 | ' | |
253 | ||
1af524eb JN |
254 | test_expect_success '-m and -F do not mix' ' |
255 | echo enough with the bongos >file && | |
256 | test_must_fail git commit -F msg -m amending . | |
257 | ' | |
258 | ||
259 | test_expect_success 'using message from other commit' ' | |
260 | git commit -C HEAD^ . | |
261 | ' | |
12ace0b2 | 262 | |
1af524eb JN |
263 | test_expect_success 'editing message from other commit' ' |
264 | cat >editor <<-\EOF && | |
265 | #!/bin/sh | |
266 | sed -e "s/amend/older/g" < "$1" > "$1-" | |
267 | mv "$1-" "$1" | |
268 | EOF | |
269 | chmod 755 editor && | |
270 | echo hula hula >file && | |
271 | EDITOR=./editor git commit -c HEAD^ -a | |
272 | ' | |
12ace0b2 | 273 | |
1af524eb JN |
274 | test_expect_success 'message from stdin' ' |
275 | echo silly new contents >file && | |
276 | echo commit message from stdin | | |
277 | git commit -F - -a | |
278 | ' | |
12ace0b2 | 279 | |
1af524eb JN |
280 | test_expect_success 'overriding author from command line' ' |
281 | echo gak >file && | |
282 | git commit -m author \ | |
283 | --author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 && | |
284 | grep Rubber.Duck output | |
285 | ' | |
12ace0b2 | 286 | |
1af524eb JN |
287 | test_expect_success PERL 'interactive add' ' |
288 | echo 7 | | |
289 | git commit --interactive | | |
290 | grep "What now" | |
291 | ' | |
292 | ||
293 | test_expect_success PERL "commit --interactive doesn't change index if editor aborts" ' | |
294 | echo zoo >file && | |
02a481fc | 295 | test_must_fail git diff --exit-code >diff1 && |
0590ff26 | 296 | test_write_lines u "*" q | |
1af524eb JN |
297 | ( |
298 | EDITOR=: && | |
299 | export EDITOR && | |
300 | test_must_fail git commit --interactive | |
301 | ) && | |
02a481fc | 302 | git diff >diff2 && |
1af524eb JN |
303 | compare_diff_patch diff1 diff2 |
304 | ' | |
12ace0b2 | 305 | |
1af524eb JN |
306 | test_expect_success 'editor not invoked if -F is given' ' |
307 | cat >editor <<-\EOF && | |
308 | #!/bin/sh | |
309 | sed -e s/good/bad/g <"$1" >"$1-" | |
310 | mv "$1-" "$1" | |
311 | EOF | |
312 | chmod 755 editor && | |
313 | ||
314 | echo A good commit message. >msg && | |
315 | echo moo >file && | |
316 | ||
317 | EDITOR=./editor git commit -a -F msg && | |
318 | git show -s --pretty=format:%s >subject && | |
319 | grep -q good subject && | |
320 | ||
321 | echo quack >file && | |
322 | echo Another good message. | | |
323 | EDITOR=./editor git commit -a -F - && | |
324 | git show -s --pretty=format:%s >subject && | |
325 | grep -q good subject | |
326 | ' | |
12ace0b2 | 327 | |
db33af0a | 328 | test_expect_success 'partial commit that involves removal (1)' ' |
80bffaf7 JH |
329 | |
330 | git rm --cached file && | |
331 | mv file elif && | |
332 | git add elif && | |
333 | git commit -m "Partial: add elif" elif && | |
334 | git diff-tree --name-status HEAD^ HEAD >current && | |
335 | echo "A elif" >expected && | |
1e368681 | 336 | test_cmp expected current |
80bffaf7 JH |
337 | |
338 | ' | |
339 | ||
db33af0a | 340 | test_expect_success 'partial commit that involves removal (2)' ' |
80bffaf7 JH |
341 | |
342 | git commit -m "Partial: remove file" file && | |
343 | git diff-tree --name-status HEAD^ HEAD >current && | |
344 | echo "D file" >expected && | |
1e368681 | 345 | test_cmp expected current |
80bffaf7 JH |
346 | |
347 | ' | |
348 | ||
db33af0a JH |
349 | test_expect_success 'partial commit that involves removal (3)' ' |
350 | ||
351 | git rm --cached elif && | |
352 | echo elif >elif && | |
353 | git commit -m "Partial: modify elif" elif && | |
354 | git diff-tree --name-status HEAD^ HEAD >current && | |
355 | echo "M elif" >expected && | |
1e368681 | 356 | test_cmp expected current |
db33af0a JH |
357 | |
358 | ' | |
359 | ||
5aa5cd46 JH |
360 | test_expect_success 'amend commit to fix author' ' |
361 | ||
362 | oldtick=$GIT_AUTHOR_DATE && | |
363 | test_tick && | |
364 | git reset --hard && | |
365 | git cat-file -p HEAD | | |
366 | sed -e "s/author.*/author $author $oldtick/" \ | |
367 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
368 | expected && | |
369 | git commit --amend --author="$author" && | |
370 | git cat-file -p HEAD > current && | |
1e368681 | 371 | test_cmp expected current |
5aa5cd46 JH |
372 | |
373 | ' | |
374 | ||
02b47cd7 MV |
375 | test_expect_success 'amend commit to fix date' ' |
376 | ||
377 | test_tick && | |
378 | newtick=$GIT_AUTHOR_DATE && | |
379 | git reset --hard && | |
380 | git cat-file -p HEAD | | |
381 | sed -e "s/author.*/author $author $newtick/" \ | |
382 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
383 | expected && | |
384 | git commit --amend --date="$newtick" && | |
385 | git cat-file -p HEAD > current && | |
386 | test_cmp expected current | |
387 | ||
388 | ' | |
389 | ||
b7242b8c JK |
390 | test_expect_success 'commit mentions forced date in output' ' |
391 | git commit --amend --date=2010-01-02T03:04:05 >output && | |
392 | grep "Date: *Sat Jan 2 03:04:05 2010" output | |
393 | ' | |
394 | ||
14ac2864 JK |
395 | test_expect_success 'commit complains about completely bogus dates' ' |
396 | test_must_fail git commit --amend --date=seventeen | |
397 | ' | |
398 | ||
399 | test_expect_success 'commit --date allows approxidate' ' | |
400 | git commit --amend \ | |
401 | --date="midnight the 12th of october, anno domini 1979" && | |
402 | echo "Fri Oct 12 00:00:00 1979 +0000" >expect && | |
403 | git log -1 --format=%ad >actual && | |
404 | test_cmp expect actual | |
4579bb41 JK |
405 | ' |
406 | ||
5aa5cd46 JH |
407 | test_expect_success 'sign off (1)' ' |
408 | ||
409 | echo 1 >positive && | |
410 | git add positive && | |
411 | git commit -s -m "thank you" && | |
412 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
413 | ( | |
e974e06d ES |
414 | echo thank you && |
415 | echo && | |
5aa5cd46 JH |
416 | git var GIT_COMMITTER_IDENT | |
417 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
418 | ) >expected && | |
82ebb0b6 | 419 | test_cmp expected actual |
5aa5cd46 JH |
420 | |
421 | ' | |
422 | ||
423 | test_expect_success 'sign off (2)' ' | |
424 | ||
425 | echo 2 >positive && | |
426 | git add positive && | |
427 | existing="Signed-off-by: Watch This <watchthis@example.com>" && | |
428 | git commit -s -m "thank you | |
429 | ||
430 | $existing" && | |
431 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
432 | ( | |
e974e06d ES |
433 | echo thank you && |
434 | echo && | |
435 | echo $existing && | |
5aa5cd46 JH |
436 | git var GIT_COMMITTER_IDENT | |
437 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
438 | ) >expected && | |
82ebb0b6 | 439 | test_cmp expected actual |
5aa5cd46 JH |
440 | |
441 | ' | |
442 | ||
c1e01b0c DB |
443 | test_expect_success 'signoff gap' ' |
444 | ||
445 | echo 3 >positive && | |
446 | git add positive && | |
447 | alt="Alt-RFC-822-Header: Value" && | |
448 | git commit -s -m "welcome | |
449 | ||
450 | $alt" && | |
451 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
452 | ( | |
e974e06d ES |
453 | echo welcome && |
454 | echo && | |
455 | echo $alt && | |
c1e01b0c DB |
456 | git var GIT_COMMITTER_IDENT | |
457 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
458 | ) >expected && | |
459 | test_cmp expected actual | |
460 | ' | |
461 | ||
462 | test_expect_success 'signoff gap 2' ' | |
463 | ||
464 | echo 4 >positive && | |
465 | git add positive && | |
466 | alt="fixed: 34" && | |
467 | git commit -s -m "welcome | |
468 | ||
469 | We have now | |
470 | $alt" && | |
471 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
472 | ( | |
e974e06d ES |
473 | echo welcome && |
474 | echo && | |
475 | echo We have now && | |
476 | echo $alt && | |
477 | echo && | |
c1e01b0c DB |
478 | git var GIT_COMMITTER_IDENT | |
479 | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" | |
480 | ) >expected && | |
481 | test_cmp expected actual | |
482 | ' | |
483 | ||
967dfd4d JT |
484 | test_expect_success 'signoff respects trailer config' ' |
485 | ||
486 | echo 5 >positive && | |
487 | git add positive && | |
488 | git commit -s -m "subject | |
489 | ||
490 | non-trailer line | |
491 | Myfooter: x" && | |
492 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
493 | ( | |
e974e06d ES |
494 | echo subject && |
495 | echo && | |
496 | echo non-trailer line && | |
497 | echo Myfooter: x && | |
498 | echo && | |
967dfd4d JT |
499 | echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" |
500 | ) >expected && | |
501 | test_cmp expected actual && | |
502 | ||
503 | echo 6 >positive && | |
504 | git add positive && | |
505 | git -c "trailer.Myfooter.ifexists=add" commit -s -m "subject | |
506 | ||
507 | non-trailer line | |
508 | Myfooter: x" && | |
509 | git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && | |
510 | ( | |
e974e06d ES |
511 | echo subject && |
512 | echo && | |
513 | echo non-trailer line && | |
514 | echo Myfooter: x && | |
967dfd4d JT |
515 | echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>" |
516 | ) >expected && | |
517 | test_cmp expected actual | |
518 | ' | |
519 | ||
5aa5cd46 JH |
520 | test_expect_success 'multiple -m' ' |
521 | ||
522 | >negative && | |
523 | git add negative && | |
524 | git commit -m "one" -m "two" -m "three" && | |
525 | git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && | |
526 | ( | |
e974e06d ES |
527 | echo one && |
528 | echo && | |
529 | echo two && | |
530 | echo && | |
5aa5cd46 JH |
531 | echo three |
532 | ) >expected && | |
82ebb0b6 | 533 | test_cmp expected actual |
5aa5cd46 JH |
534 | |
535 | ' | |
536 | ||
d63c2fd1 KH |
537 | test_expect_success 'amend commit to fix author' ' |
538 | ||
539 | oldtick=$GIT_AUTHOR_DATE && | |
540 | test_tick && | |
541 | git reset --hard && | |
542 | git cat-file -p HEAD | | |
543 | sed -e "s/author.*/author $author $oldtick/" \ | |
544 | -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ | |
545 | expected && | |
546 | git commit --amend --author="$author" && | |
547 | git cat-file -p HEAD > current && | |
1e368681 | 548 | test_cmp expected current |
d63c2fd1 KH |
549 | |
550 | ' | |
1200993a KH |
551 | |
552 | test_expect_success 'git commit <file> with dirty index' ' | |
553 | echo tacocat > elif && | |
554 | echo tehlulz > chz && | |
555 | git add chz && | |
556 | git commit elif -m "tacocat is a palindrome" && | |
557 | git show --stat | grep elif && | |
558 | git diff --cached | grep chz | |
559 | ' | |
560 | ||
13aba1e5 JS |
561 | test_expect_success 'same tree (single parent)' ' |
562 | ||
1af524eb JN |
563 | git reset --hard && |
564 | test_must_fail git commit -m empty | |
13aba1e5 JS |
565 | |
566 | ' | |
567 | ||
36863af1 JH |
568 | test_expect_success 'same tree (single parent) --allow-empty' ' |
569 | ||
570 | git commit --allow-empty -m "forced empty" && | |
571 | git cat-file commit HEAD | grep forced | |
572 | ||
573 | ' | |
574 | ||
13aba1e5 JS |
575 | test_expect_success 'same tree (merge and amend merge)' ' |
576 | ||
577 | git checkout -b side HEAD^ && | |
578 | echo zero >zero && | |
579 | git add zero && | |
580 | git commit -m "add zero" && | |
581 | git checkout master && | |
582 | ||
583 | git merge -s ours side -m "empty ok" && | |
584 | git diff HEAD^ HEAD >actual && | |
585 | : >expected && | |
82ebb0b6 | 586 | test_cmp expected actual && |
13aba1e5 JS |
587 | |
588 | git commit --amend -m "empty really ok" && | |
589 | git diff HEAD^ HEAD >actual && | |
590 | : >expected && | |
82ebb0b6 | 591 | test_cmp expected actual |
13aba1e5 JS |
592 | |
593 | ' | |
594 | ||
1eb1e9ee JH |
595 | test_expect_success 'amend using the message from another commit' ' |
596 | ||
597 | git reset --hard && | |
598 | test_tick && | |
599 | git commit --allow-empty -m "old commit" && | |
600 | old=$(git rev-parse --verify HEAD) && | |
601 | test_tick && | |
602 | git commit --allow-empty -m "new commit" && | |
603 | new=$(git rev-parse --verify HEAD) && | |
604 | test_tick && | |
605 | git commit --allow-empty --amend -C "$old" && | |
606 | git show --pretty="format:%ad %s" "$old" >expected && | |
607 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 608 | test_cmp expected actual |
1eb1e9ee JH |
609 | |
610 | ' | |
611 | ||
8a2f8733 JH |
612 | test_expect_success 'amend using the message from a commit named with tag' ' |
613 | ||
614 | git reset --hard && | |
615 | test_tick && | |
616 | git commit --allow-empty -m "old commit" && | |
617 | old=$(git rev-parse --verify HEAD) && | |
618 | git tag -a -m "tag on old" tagged-old HEAD && | |
619 | test_tick && | |
620 | git commit --allow-empty -m "new commit" && | |
621 | new=$(git rev-parse --verify HEAD) && | |
622 | test_tick && | |
623 | git commit --allow-empty --amend -C tagged-old && | |
624 | git show --pretty="format:%ad %s" "$old" >expected && | |
625 | git show --pretty="format:%ad %s" HEAD >actual && | |
82ebb0b6 | 626 | test_cmp expected actual |
8a2f8733 JH |
627 | |
628 | ' | |
629 | ||
6360d343 TR |
630 | test_expect_success 'amend can copy notes' ' |
631 | ||
632 | git config notes.rewrite.amend true && | |
633 | git config notes.rewriteRef "refs/notes/*" && | |
634 | test_commit foo && | |
635 | git notes add -m"a note" && | |
636 | test_tick && | |
637 | git commit --amend -m"new foo" && | |
638 | test "$(git notes show)" = "a note" | |
639 | ||
640 | ' | |
641 | ||
4682d852 JH |
642 | test_expect_success 'commit a file whose name is a dash' ' |
643 | git reset --hard && | |
644 | for i in 1 2 3 4 5 | |
645 | do | |
646 | echo $i | |
647 | done >./- && | |
648 | git add ./- && | |
649 | test_tick && | |
650 | git commit -m "add dash" >output </dev/null && | |
651 | test_i18ngrep " changed, 5 insertions" output | |
652 | ' | |
653 | ||
f0c73200 TR |
654 | test_expect_success '--only works on to-be-born branch' ' |
655 | # This test relies on having something in the index, as it | |
656 | # would not otherwise actually prove much. So check this. | |
657 | test -n "$(git ls-files)" && | |
658 | git checkout --orphan orphan && | |
659 | echo foo >newfile && | |
660 | git add newfile && | |
661 | git commit --only newfile -m"--only on unborn branch" && | |
662 | echo newfile >expected && | |
663 | git ls-tree -r --name-only HEAD >actual && | |
664 | test_cmp expected actual | |
665 | ' | |
666 | ||
8dc874b2 SS |
667 | test_expect_success '--dry-run with conflicts fixed from a merge' ' |
668 | # setup two branches with conflicting information | |
669 | # in the same file, resolve the conflict, | |
670 | # call commit with --dry-run | |
671 | echo "Initial contents, unimportant" >test-file && | |
672 | git add test-file && | |
673 | git commit -m "Initial commit" && | |
674 | echo "commit-1-state" >test-file && | |
675 | git commit -m "commit 1" -i test-file && | |
676 | git tag commit-1 && | |
677 | git checkout -b branch-2 HEAD^1 && | |
678 | echo "commit-2-state" >test-file && | |
679 | git commit -m "commit 2" -i test-file && | |
680 | ! $(git merge --no-commit commit-1) && | |
681 | echo "commit-2-state" >test-file && | |
682 | git add test-file && | |
683 | git commit --dry-run && | |
684 | git commit -m "conflicts fixed from merge." | |
685 | ' | |
686 | ||
12ace0b2 | 687 | test_done |