@matheusbsbs / matheus-bagliano / commits / 756ee7fc9f
Fork 0

t7501: stop losing return codes of git commands

In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream so that we will know if a command fails. In the 'interactive add' test case, we prepend a `test_must_fail` to `git commit --interactive`. When there are no changes to commit, `git commit` will exit with status code 1. Following along with the rest of the file, we use `test_must_fail` to test for this case. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Nov 27, 2019 at 11:53 UTC 756ee7fc9fcf599e807a27e45a9d0fb89e8411a8
1 file changed +39 -30
t/t7501-commit-basic-functionality.sh
+39 -30
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
285 '
286
287 test_expect_success PERL 'interactive add' '
288 - echo 7 |
289 - git commit --interactive |
290 - grep "What now"
288 + echo 7 | test_must_fail git commit --interactive >out &&
289 + grep "What now" out
290 '
291
292 test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@@ -362,10 +361,10 @@ test_expect_success 'amend commit to fix author' '
361 oldtick=$GIT_AUTHOR_DATE &&
362 test_tick &&
363 git reset --hard &&
365 - git cat-file -p HEAD |
364 + git cat-file -p HEAD >commit &&
365 sed -e "s/author.*/author $author $oldtick/" \
367 - -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
368 - expected &&
366 + -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
367 + commit >expected &&
368 git commit --amend --author="$author" &&
369 git cat-file -p HEAD >current &&
370 test_cmp expected current
@@ -377,10 +376,10 @@ test_expect_success 'amend commit to fix date' '
376 test_tick &&
377 newtick=$GIT_AUTHOR_DATE &&
378 git reset --hard &&
380 - git cat-file -p HEAD |
379 + git cat-file -p HEAD >commit &&
380 sed -e "s/author.*/author $author $newtick/" \
382 - -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
383 - expected &&
381 + -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
382 + commit >expected &&
383 git commit --amend --date="$newtick" &&
384 git cat-file -p HEAD >current &&
385 test_cmp expected current
@@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' '
408 echo 1 >positive &&
409 git add positive &&
410 git commit -s -m "thank you" &&
412 - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
411 + git cat-file commit HEAD >commit &&
412 + sed -e "1,/^\$/d" commit >actual &&
413 (
414 echo thank you &&
415 echo &&
416 - git var GIT_COMMITTER_IDENT |
417 - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
416 + git var GIT_COMMITTER_IDENT >ident &&
417 + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
418 ) >expected &&
419 test_cmp expected actual
420
@@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' '
428 git commit -s -m "thank you
429
430 $existing" &&
431 - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
431 + git cat-file commit HEAD >commit &&
432 + sed -e "1,/^\$/d" commit >actual &&
433 (
434 echo thank you &&
435 echo &&
436 echo $existing &&
436 - git var GIT_COMMITTER_IDENT |
437 - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
437 + git var GIT_COMMITTER_IDENT >ident &&
438 + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
439 ) >expected &&
440 test_cmp expected actual
441
@@ -448,13 +449,14 @@ test_expect_success 'signoff gap' '
449 git commit -s -m "welcome
450
451 $alt" &&
451 - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
452 + git cat-file commit HEAD >commit &&
453 + sed -e "1,/^\$/d" commit >actual &&
454 (
455 echo welcome &&
456 echo &&
457 echo $alt &&
456 - git var GIT_COMMITTER_IDENT |
457 - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
458 + git var GIT_COMMITTER_IDENT >ident &&
459 + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
460 ) >expected &&
461 test_cmp expected actual
462 '
@@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' '
470
471 We have now
472 $alt" &&
471 - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
473 + git cat-file commit HEAD >commit &&
474 + sed -e "1,/^\$/d" commit >actual &&
475 (
476 echo welcome &&
477 echo &&
478 echo We have now &&
479 echo $alt &&
480 echo &&
478 - git var GIT_COMMITTER_IDENT |
479 - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
481 + git var GIT_COMMITTER_IDENT >ident &&
482 + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
483 ) >expected &&
484 test_cmp expected actual
485 '
@@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' '
492
493 non-trailer line
494 Myfooter: x" &&
492 - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
495 + git cat-file commit HEAD >commit &&
496 + sed -e "1,/^\$/d" commit >actual &&
497 (
498 echo subject &&
499 echo &&
@@ -506,7 +510,8 @@ Myfooter: x" &&
510
511 non-trailer line
512 Myfooter: x" &&
509 - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
513 + git cat-file commit HEAD >commit &&
514 + sed -e "1,/^\$/d" commit >actual &&
515 (
516 echo subject &&
517 echo &&
@@ -538,7 +543,8 @@ test_expect_success 'multiple -m' '
543 >negative &&
544 git add negative &&
545 git commit -m "one" -m "two" -m "three" &&
541 - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
546 + git cat-file commit HEAD >commit &&
547 + sed -e "1,/^\$/d" commit >actual &&
548 (
549 echo one &&
550 echo &&
@@ -555,10 +561,10 @@ test_expect_success 'amend commit to fix author' '
561 oldtick=$GIT_AUTHOR_DATE &&
562 test_tick &&
563 git reset --hard &&
558 - git cat-file -p HEAD |
564 + git cat-file -p HEAD >commit &&
565 sed -e "s/author.*/author $author $oldtick/" \
560 - -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
561 - expected &&
566 + -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
567 + commit >expected &&
568 git commit --amend --author="$author" &&
569 git cat-file -p HEAD >current &&
570 test_cmp expected current
@@ -570,8 +576,10 @@ test_expect_success 'git commit <file> with dirty index' '
576 echo tehlulz >chz &&
577 git add chz &&
578 git commit elif -m "tacocat is a palindrome" &&
573 - git show --stat | grep elif &&
574 - git diff --cached | grep chz
579 + git show --stat >stat &&
580 + grep elif stat &&
581 + git diff --cached >diff &&
582 + grep chz diff
583 '
584
585 test_expect_success 'same tree (single parent)' '
@@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' '
592 test_expect_success 'same tree (single parent) --allow-empty' '
593
594 git commit --allow-empty -m "forced empty" &&
587 - git cat-file commit HEAD | grep forced
595 + git cat-file commit HEAD >commit &&
596 + grep forced commit
597
598 '
599