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