git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Usman Akinyemi via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,
	Christian Couder <christian.couder@gmail.com>,
	Phillip Wood Phillip Wood <phillip.wood@dunelm.org.uk>,
	Eric Sunshine <sunshine@sunshineco.com>,
	shejialuo <shejialuo@gmail.com>,
	Usman Akinyemi <usmanakinyemi202@gmail.com>
Subject: Re: [PATCH v3 1/2] t3404: avoid losing exit status with focus on `git show` and `git cat-files`
Date: Mon, 7 Oct 2024 08:04:59 +0200	[thread overview]
Message-ID: <ZwN6BNPHiXyKGd1t@pks.im> (raw)
In-Reply-To: <c9a0cca179bfad129017c7f1085ff87201afb417.1728230769.git.gitgitgadget@gmail.com>

On Sun, Oct 06, 2024 at 04:06:08PM +0000, Usman Akinyemi via GitGitGadget wrote:
> From: Usman Akinyemi <usmanakinyemi202@gmail.com>
> 
> The exit code of the preceding command in a pipe is disregarded. So
> if that preceding command is a Git command that fails, the test would
> not fail. Instead, by saving the output of that Git command to a file,
> and removing the pipe, we make sure the test will fail if that Git
> command fails. This particular patch focuses on some of the instances
> which include `git show` and `git cat-files`.

Well-described.

> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
> ---
>  t/t3404-rebase-interactive.sh | 71 +++++++++++++++++++++++------------
>  1 file changed, 48 insertions(+), 23 deletions(-)
> 
> diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
> index f171af3061d..96a65783c47 100755
> --- a/t/t3404-rebase-interactive.sh
> +++ b/t/t3404-rebase-interactive.sh
> @@ -319,7 +319,8 @@ test_expect_success 'retain authorship' '
>  	GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
>  	git tag twerp &&
>  	git rebase -i --onto primary HEAD^ &&
> -	git show HEAD | grep "^Author: Twerp Snog"
> +	git show HEAD >actual &&
> +	grep "^Author: Twerp Snog" actual
>  '

One thing to note is that it would be preferable to use `test_grep`
instead of `grep` here. `test_grep` brings in some additional benefits
over plain `grep` like better diagnosis of issues, and it would also
print the file if things didn't match. That makes it way easier e.g. in
our CI to see what the actual output was.

There is no need to reroll this patch series just because of that
though, as your changes are a strict improvement by themselves already.
But if you do end up rerolling it would be nice to incorporate this.

> @@ -397,7 +400,9 @@ test_expect_success 'multi-squash only fires up editor once' '
>  			git rebase -i $base
>  	) &&
>  	test $base = $(git rev-parse HEAD^) &&
> -	test 1 = $(git show | grep ONCE | wc -l)
> +	git show >output &&
> +	count=$(grep ONCE output | wc -l) &&
> +	test 1 = $count
>  '
>  
>  test_expect_success 'multi-fixup does not fire up editor' '

I was wondering whether the following might be nicer:

    git show >output &&
    grep ONCE output >output.filtered &&
    test_line_count = 1 output.filtered

But after seeing this I don't strongly lean into one or another
direction. So please feel free to use either your current or my proposed
style, I'm fine with either.

> @@ -470,10 +481,10 @@ test_expect_success 'squash and fixup generate correct log messages' '
>  	) &&
>  	git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
>  	test_cmp expect-squash-fixup actual-squash-fixup &&
> -	git cat-file commit HEAD@{2} |
> -		grep "^# This is a combination of 3 commits\."  &&
> -	git cat-file commit HEAD@{3} |
> -		grep "^# This is a combination of 2 commits\."  &&
> +	git cat-file commit HEAD@{2} >actual &&
> +	grep "^# This is a combination of 3 commits\." actual &&
> +	git cat-file commit HEAD@{3} >actual &&
> +	grep "^# This is a combination of 2 commits\." actual  &&
>  	git checkout @{-1} &&
>  	git branch -D squash-fixup
>  '

Nice cleanups while at it.

Patrick

  reply	other threads:[~2024-10-07  6:05 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-06  5:33 [PATCH 0/2] [Outreachy][Patch v2] t3404: avoid losing exit status to pipes Usman Akinyemi via GitGitGadget
2024-10-06  5:33 ` [PATCH 1/2] [Outreachy][Patch v1] " Usman Akinyemi via GitGitGadget
2024-10-06  5:55   ` Eric Sunshine
2024-10-06  6:31     ` Usman Akinyemi
2024-10-06  5:33 ` [PATCH 2/2] [Outreachy][Patch v2] " Usman Akinyemi via GitGitGadget
2024-10-06  5:48   ` Eric Sunshine
2024-10-06  6:30     ` Usman Akinyemi
2024-10-06  7:28       ` Eric Sunshine
2024-10-06  8:26         ` Usman Akinyemi
2024-10-06  8:31 ` [PATCH v2] [Outreachy][Patch v1] " Usman Akinyemi via GitGitGadget
2024-10-06  9:19   ` Eric Sunshine
2024-10-06  9:32     ` Usman Akinyemi
2024-10-06 10:21       ` Eric Sunshine
2024-10-06 11:12     ` shejialuo
2024-10-06 12:06       ` Eric Sunshine
2024-10-06 12:28         ` Usman Akinyemi
2024-10-06 13:03           ` shejialuo
2024-10-06 13:27             ` Usman Akinyemi
2024-10-06 13:36               ` shejialuo
2024-10-06 12:29         ` shejialuo
2024-10-06 12:46           ` Usman Akinyemi
2024-10-07  4:19           ` Eric Sunshine
2024-10-06 16:06   ` [PATCH v3 0/2] [Outreachy][Patch v2] " Usman Akinyemi via GitGitGadget
2024-10-06 16:06     ` [PATCH v3 1/2] t3404: avoid losing exit status with focus on `git show` and `git cat-files` Usman Akinyemi via GitGitGadget
2024-10-07  6:04       ` Patrick Steinhardt [this message]
2024-10-07  8:52       ` phillip.wood123
2024-10-07  9:05         ` Usman Akinyemi
2024-10-06 16:06     ` [PATCH v3 2/2] [Outreachy][Patch v1] t3404: employing test_line_count() to replace test Usman Akinyemi via GitGitGadget
2024-10-06 16:31       ` Kristoffer Haugsbakk
2024-10-07  4:38       ` Eric Sunshine
2024-10-07  6:05       ` Patrick Steinhardt
2024-10-07  7:32         ` Usman Akinyemi
2024-10-07  9:00         ` phillip.wood123
2024-10-06 16:18     ` [PATCH v3 0/2] [Outreachy][Patch v2] t3404: avoid losing exit status to pipes Usman Akinyemi
2024-10-07  4:24       ` Eric Sunshine
2024-10-07  7:25         ` Usman Akinyemi
2024-10-07  8:08           ` Patrick Steinhardt
2024-10-07  8:11             ` Eric Sunshine
2024-10-07  9:01               ` Usman Akinyemi
2024-10-06 16:21     ` Kristoffer Haugsbakk
2024-10-06 16:26       ` Usman Akinyemi
2024-10-07  5:55         ` Patrick Steinhardt
2024-10-07 10:22     ` [PATCH v4 " Usman Akinyemi via GitGitGadget
2024-10-07 10:22       ` [PATCH v4 1/2] t3404: avoid losing exit status with focus on `git show` and `git cat-file` Usman Akinyemi via GitGitGadget
2024-10-07 10:22       ` [PATCH v4 2/2] [Outreachy][Patch v1] t3404: employing test_line_count() to replace test Usman Akinyemi via GitGitGadget
2024-10-07 10:28         ` Patrick Steinhardt
2024-10-07 10:51       ` [PATCH v5 0/2] [Outreachy][Patch v2] t3404: avoid losing exit status to pipes Usman Akinyemi via GitGitGadget
2024-10-07 10:51         ` [PATCH v5 1/2] t3404: avoid losing exit status with focus on `git show` and `git cat-file` Usman Akinyemi via GitGitGadget
2024-10-07 10:51         ` [PATCH v5 2/2] t3404: employing test_line_count() to replace test Usman Akinyemi via GitGitGadget
2024-10-07 10:54           ` Patrick Steinhardt
2024-10-07 11:10             ` Usman Akinyemi
2024-10-07 11:11         ` [PATCH v6 0/2] [Outreachy][Patch v2] t3404: avoid losing exit status to pipes Usman Akinyemi via GitGitGadget
2024-10-07 11:11           ` [PATCH v6 1/2] t3404: avoid losing exit status with focus on `git show` and `git cat-file` Usman Akinyemi via GitGitGadget
2024-10-07 11:11           ` [PATCH v6 2/2] t3404: employing test_line_count() to replace test Usman Akinyemi via GitGitGadget
2024-10-07 15:07             ` Phillip Wood
2024-10-07 15:32               ` Usman Akinyemi
2024-10-07 11:12           ` [PATCH v6 0/2] [Outreachy][Patch v2] t3404: avoid losing exit status to pipes Patrick Steinhardt
2024-10-07 11:16             ` Usman Akinyemi
2024-10-07 11:32               ` Patrick Steinhardt
2024-10-07 11:44                 ` Usman Akinyemi
2024-10-07 15:32           ` [PATCH v7 " Usman Akinyemi via GitGitGadget
2024-10-07 15:32             ` [PATCH v7 1/2] t3404: avoid losing exit status with focus on `git show` and `git cat-file` Usman Akinyemi via GitGitGadget
2024-10-07 15:32             ` [PATCH v7 2/2] t3404: replace test with test_line_count() Usman Akinyemi via GitGitGadget

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZwN6BNPHiXyKGd1t@pks.im \
    --to=ps@pks.im \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=shejialuo@gmail.com \
    --cc=sunshine@sunshineco.com \
    --cc=usmanakinyemi202@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).