threads / patch / 54449

patch, 2 partst9832,t2200: avoid using pipes in git related commands

Subject: [PATCH 0/2] [Outreachy][Patch v1] t9832,t2200: avoid using pipes in git related commands

## tl;dr

14 messages between Oct 17, 2020 and Oct 18, 2020. Diffs are folded; open one to read it.

replies: 13people: 3as markdown or json

Amanda Shafack via GitGitGadget· Oct 17, 2020, 16:02 UTC · lore

When the upstream of a pipe throws an error, the downstream still executes normally. This happens because the exit code of the upstream in a pipe is ignored. This behavior can make debugging very hard in case a test fails. Also, pipes are prone to deadlocks. If the upstream gets full, the commands downstream will never start.

Write out the output of the git command to a file, so as to test the exit codes of both commands.

Commit c6f44e1da5 (t9813: avoid using pipes, 2017-01-04) noticed that the exit code of upstream in the pipe is ignored, thus using pipes should be avoided.

Signed-off-by: Amanda Shafack shafack.likhene@gmail.com
[shafack.likhene@gmail.com]
Amanda  Shafack (1):
  t2200: modify code syntax
Amanda Shafack (1):
  t9832,t2200: avoid using pipes in git commands
 t/t2200-add-update.sh | 3 ++-
 t/t9832-unshelve.sh   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
base-commit: a5fa49ff0a8f3252c6bff49f92b85e7683868f8a
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-885%2Flkmandy%2Favoid-pipes-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-885/lkmandy/avoid-pipes-v1
Pull-Request: https://github.com/git/git/pull/885
-- 
gitgitgadget
Amanda Shafack via GitGitGadget· Oct 17, 2020, 16:02 UTC · re: Amanda Shafack via GitGitGadget · lore

[PATCH 2/2] t2200: modify code syntax

From: Amanda  Shafack <shafack.likhene@gmail.com>

Using the logical not operator on both the git and grep command is redundant, since the main check is done at the level of the grep command.

Apply the logical not operator only to the grep command.
Co-authored-by: Johannes Schindelin <dscho@github.com>
Signed-off-by: Amanda Shafack <shafack.likhene@gmail.com>
---
 t/t2200-add-update.sh | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Show changes to t/t2200-add-update.sh +2 −4
diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index 2d850bb372..7cb7a70382 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -179,10 +179,8 @@ test_expect_success 'add -u resolves unmerged paths' '
 
 test_expect_success '"add -u non-existent" should fail' '
 	test_must_fail git add -u non-existent &&
-	! (
-		git ls-files >actual &&
-		grep "non-existent" actual
-	)
+	git ls-files >actual &&
+	! grep "non-existent" actual
 '
 
 test_done
-- 
gitgitgadget
Eric Sunshine· Oct 18, 2020, 05:55 UTC · re: Amanda Shafack via GitGitGadget · lore

Re: [PATCH 2/2] t2200: modify code syntax

On Sat, Oct 17, 2020 at 12:02 PM Amanda Shafack via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 14 quoted lines
> Using the logical not operator on both the git and grep command is
> redundant, since the main check is done at the level of the grep
> command.
>
> Apply the logical not operator only to the grep command.
> ---
> diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
> @@ -179,10 +179,8 @@ test_expect_success 'add -u resolves unmerged paths' '
> -       ! (
> -               git ls-files >actual &&
> -               grep "non-existent" actual
> -       )
> +       git ls-files >actual &&
> +       ! grep "non-existent" actual

The commit message talks only about redundancy of applying the logical NOT operator to the combined subshell content, but what it misses is that transformation of:

    ! (git ls-files | grep "non-existent")
in patch [1/2] into:
    ! (
        git ls-files >actual &&
        grep "non-existent" actual
    )

is actively wrong. In particular, if `git ls-files` itself fails, then the `grep` will never get run, and the subshell will exit with a failure, however, the NOT then turns that failure into a success, which is quite undesirable. The test should fail if either `git ls-files` fails or if the `grep` expectation is not met; it should not succeed when `git ls-files` fails.

So, the correct thing to do is to merge [1/2] and [2/2] into a single patch which directly transforms:

    ! (git ls-files | grep "non-existent")
into:
    git ls-files >actual &&
    ! grep "non-existent" actual
Amanda Shafack· Oct 18, 2020, 13:59 UTC · re: Eric Sunshine · lore

Re: [PATCH 2/2] t2200: modify code syntax

I agree with you. I have made these changes as well. Thanks

On Sun, Oct 18, 2020 at 6:56 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 47 quoted lines
>
> On Sat, Oct 17, 2020 at 12:02 PM Amanda Shafack via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > Using the logical not operator on both the git and grep command is
> > redundant, since the main check is done at the level of the grep
> > command.
> >
> > Apply the logical not operator only to the grep command.
> > ---
> > diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
> > @@ -179,10 +179,8 @@ test_expect_success 'add -u resolves unmerged paths' '
> > -       ! (
> > -               git ls-files >actual &&
> > -               grep "non-existent" actual
> > -       )
> > +       git ls-files >actual &&
> > +       ! grep "non-existent" actual
>
> The commit message talks only about redundancy of applying the logical
> NOT operator to the combined subshell content, but what it misses is
> that transformation of:
>
>     ! (git ls-files | grep "non-existent")
>
> in patch [1/2] into:
>
>     ! (
>         git ls-files >actual &&
>         grep "non-existent" actual
>     )
>
> is actively wrong. In particular, if `git ls-files` itself fails, then
> the `grep` will never get run, and the subshell will exit with a
> failure, however, the NOT then turns that failure into a success,
> which is quite undesirable. The test should fail if either `git
> ls-files` fails or if the `grep` expectation is not met; it should not
> succeed when `git ls-files` fails.
>
> So, the correct thing to do is to merge [1/2] and [2/2] into a single
> patch which directly transforms:
>
>     ! (git ls-files | grep "non-existent")
>
> into:
>
>     git ls-files >actual &&
>     ! grep "non-existent" actual
-- 
Cheers!

Amanda  Shafack
Amanda Shafack via GitGitGadget· Oct 17, 2020, 16:02 UTC · re: Amanda Shafack via GitGitGadget · lore

[PATCH 1/2] t9832,t2200: avoid using pipes in git commands

From: Amanda Shafack <shafack.likhene@gmail.com>

When the upstream of a pipe throws an error, the downstream still executes normally. This happens because the exit code of the upstream in a pipe is ignored. This behavior can make debugging very hard incase a test fails. Also, pipes are prone to deadlocks. If the upstream gets full, the commands downstream will never start.

Write out the output of the git command to a file, so as to test the exit codes of both commands.

Commit c6f44e1da5 (t9813: avoid using pipes, 2017-01-04) noticed that the exit code of upstream in the pipe is ignored, thus using pipes should be avoided.

Signed-off-by: Amanda Shafack <shafack.likhene@gmail.com>
---
 t/t2200-add-update.sh | 5 ++++-
 t/t9832-unshelve.sh   | 3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)
Show changes to 2 files +6 −2

t/t2200-add-update.sh, t/t9832-unshelve.sh

diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index f764b7e3f5..2d850bb372 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -179,7 +179,10 @@ test_expect_success 'add -u resolves unmerged paths' '
 
 test_expect_success '"add -u non-existent" should fail' '
 	test_must_fail git add -u non-existent &&
-	! (git ls-files | grep "non-existent")
+	! (
+		git ls-files >actual &&
+		grep "non-existent" actual
+	)
 '
 
 test_done
diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh
index 7194fb2855..6b3cb0414a 100755
--- a/t/t9832-unshelve.sh
+++ b/t/t9832-unshelve.sh
@@ -68,7 +68,8 @@ EOF
 		cd "$git" &&
 		change=$(last_shelved_change) &&
 		git p4 unshelve $change &&
-		git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
+		git show refs/remotes/p4-unshelved/$change >actual &&
+		grep -q "Further description" actual &&
 		git cherry-pick refs/remotes/p4-unshelved/$change &&
 		test_path_is_file file2 &&
 		test_cmp file1 "$cli"/file1 &&
-- 
gitgitgadget
Eric Sunshine· Oct 18, 2020, 06:11 UTC · re: Amanda Shafack via GitGitGadget · lore

Re: [PATCH 1/2] t9832,t2200: avoid using pipes in git commands

On Sat, Oct 17, 2020 at 12:02 PM Amanda Shafack via GitGitGadget <gitgitgadget@gmail.com> wrote:

> When the upstream of a pipe throws an error, the downstream still
> executes normally. This happens because the exit code of the upstream
> in a pipe is ignored. This behavior can make debugging very hard
> incase a test fails.

To be more precise, we're not worried about difficulty of debugging when a Git command is upstream in a pipe. What we are more concerned with is that an unexpected failure of the Git command will go unnoticed (unless it also happens to produce wrong output which is later caught somewhere downstream). By avoiding placing Git upstream in a pipe, we can actively catch a failure of the Git command. The commit message should focus on that reason instead.

> Also, pipes are prone to deadlocks. If the
> upstream gets full, the commands downstream will never start.

I don't think this is ever an issue in Git tests, so talking about it here probably only muddies the waters, thus makes the commit message less precise and more hand-wavy. Dropping this sentence is recommended.

> Commit c6f44e1da5 (t9813: avoid using pipes, 2017-01-04) noticed that
> the exit code of upstream in the pipe is ignored, thus using pipes
> should be avoided.

There are a lot of commits in the project history which perform this sort of transformation, so it's not clear to the reader why this particular commit is called out as being important. If it's not, then I'd recommend dropping this sentence, as well.

Show 9 quoted lines
> diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
>  test_expect_success '"add -u non-existent" should fail' '
>         test_must_fail git add -u non-existent &&
> -       ! (git ls-files | grep "non-existent")
> +       ! (
> +               git ls-files >actual &&
> +               grep "non-existent" actual
> +       )
>  '

This transformation appears to be incorrect. See my review of patch [2/2] for details.

Show 5 quoted lines
> diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh
> @@ -68,7 +68,8 @@ EOF
> -               git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
> +               git show refs/remotes/p4-unshelved/$change >actual &&
> +               grep -q "Further description" actual &&
This transformation looks fine.
Amanda Shafack· Oct 18, 2020, 13:57 UTC · re: Eric Sunshine · lore

Re: [PATCH 1/2] t9832,t2200: avoid using pipes in git commands

Thanks for your feedback, I now have a better understanding. I have made the changes you requested.

On Sun, Oct 18, 2020 at 7:11 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 53 quoted lines
>
> On Sat, Oct 17, 2020 at 12:02 PM Amanda Shafack via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > When the upstream of a pipe throws an error, the downstream still
> > executes normally. This happens because the exit code of the upstream
> > in a pipe is ignored. This behavior can make debugging very hard
> > incase a test fails.
>
> To be more precise, we're not worried about difficulty of debugging
> when a Git command is upstream in a pipe. What we are more concerned
> with is that an unexpected failure of the Git command will go
> unnoticed (unless it also happens to produce wrong output which is
> later caught somewhere downstream). By avoiding placing Git upstream
> in a pipe, we can actively catch a failure of the Git command. The
> commit message should focus on that reason instead.
>
> > Also, pipes are prone to deadlocks. If the
> > upstream gets full, the commands downstream will never start.
>
> I don't think this is ever an issue in Git tests, so talking about it
> here probably only muddies the waters, thus makes the commit message
> less precise and more hand-wavy. Dropping this sentence is
> recommended.
>
> > Commit c6f44e1da5 (t9813: avoid using pipes, 2017-01-04) noticed that
> > the exit code of upstream in the pipe is ignored, thus using pipes
> > should be avoided.
>
> There are a lot of commits in the project history which perform this
> sort of transformation, so it's not clear to the reader why this
> particular commit is called out as being important. If it's not, then
> I'd recommend dropping this sentence, as well.
>
> > diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
> >  test_expect_success '"add -u non-existent" should fail' '
> >         test_must_fail git add -u non-existent &&
> > -       ! (git ls-files | grep "non-existent")
> > +       ! (
> > +               git ls-files >actual &&
> > +               grep "non-existent" actual
> > +       )
> >  '
>
> This transformation appears to be incorrect. See my review of patch
> [2/2] for details.
>
> > diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh
> > @@ -68,7 +68,8 @@ EOF
> > -               git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
> > +               git show refs/remotes/p4-unshelved/$change >actual &&
> > +               grep -q "Further description" actual &&
>
> This transformation looks fine.
-- 
Cheers!

Amanda  Shafack
Amanda Shafack via GitGitGadget· Oct 18, 2020, 14:42 UTC · re: Amanda Shafack via GitGitGadget · lore

[PATCH v2] t9832,t2200: avoid using pipes in git commands

From: Amanda Shafack <shafack.likhene@gmail.com>

When a git command is upstream in a pipe, an unexpected failure of the git command will go unnoticed.

Write out the output of the git command to a file, so as to actively catch a failure of the git command.

Signed-off-by: Amanda Shafack <shafack.likhene@gmail.com>
---
    [Outreachy][Patch v2] t9832,t2200: avoid using pipes in git related
    commands
    
    Changes since v1:
    
     * Merged patch [1/2] and [2/2] into a single patch
     * Revised commit message
    
    Signed-off-by: Amanda Shafack shafack.likhene@gmail.com
    [shafack.likhene@gmail.com]
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-885%2Flkmandy%2Favoid-pipes-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-885/lkmandy/avoid-pipes-v2
Pull-Request: https://github.com/git/git/pull/885
Range-diff vs v1:
 1:  fc2da014a6 ! 1:  bca393e69a t9832,t2200: avoid using pipes in git commands
     @@ Metadata
       ## Commit message ##
          t9832,t2200: avoid using pipes in git commands
      
     -    When the upstream of a pipe throws an error, the downstream still
     -    executes normally. This happens because the exit code of the upstream
     -    in a pipe is ignored. This behavior can make debugging very hard
     -    incase a test fails. Also, pipes are prone to deadlocks. If the
     -    upstream gets full, the commands downstream will never start.
     +    When a git command is upstream in a pipe, an unexpected failure of
     +    the git command will go unnoticed.
      
     -    Write out the output of the git command to a file, so as to test the
     -    exit codes of both commands.
     -
     -    Commit c6f44e1da5 (t9813: avoid using pipes, 2017-01-04) noticed that
     -    the exit code of upstream in the pipe is ignored, thus using pipes
     -    should be avoided.
     +    Write out the output of the git command to a file, so as to actively
     +    catch a failure of the git command.
      
          Signed-off-by: Amanda Shafack <shafack.likhene@gmail.com>
      
     @@ t/t2200-add-update.sh: test_expect_success 'add -u resolves unmerged paths' '
       test_expect_success '"add -u non-existent" should fail' '
       	test_must_fail git add -u non-existent &&
      -	! (git ls-files | grep "non-existent")
     -+	! (
     -+		git ls-files >actual &&
     -+		grep "non-existent" actual
     -+	)
     ++	git ls-files >actual &&
     ++	! grep "non-existent" actual
       '
       
       test_done
 2:  0a1550cb22 < -:  ---------- t2200: modify code syntax
 t/t2200-add-update.sh | 3 ++-
 t/t9832-unshelve.sh   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
Show changes to 2 files +4 −2

t/t2200-add-update.sh, t/t9832-unshelve.sh

diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index f764b7e3f5..7cb7a70382 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -179,7 +179,8 @@ test_expect_success 'add -u resolves unmerged paths' '
 
 test_expect_success '"add -u non-existent" should fail' '
 	test_must_fail git add -u non-existent &&
-	! (git ls-files | grep "non-existent")
+	git ls-files >actual &&
+	! grep "non-existent" actual
 '
 
 test_done
diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh
index 7194fb2855..6b3cb0414a 100755
--- a/t/t9832-unshelve.sh
+++ b/t/t9832-unshelve.sh
@@ -68,7 +68,8 @@ EOF
 		cd "$git" &&
 		change=$(last_shelved_change) &&
 		git p4 unshelve $change &&
-		git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
+		git show refs/remotes/p4-unshelved/$change >actual &&
+		grep -q "Further description" actual &&
 		git cherry-pick refs/remotes/p4-unshelved/$change &&
 		test_path_is_file file2 &&
 		test_cmp file1 "$cli"/file1 &&

base-commit: a5fa49ff0a8f3252c6bff49f92b85e7683868f8a
-- 
gitgitgadget
Eric Sunshine· Oct 18, 2020, 19:25 UTC · re: Amanda Shafack via GitGitGadget · lore

Re: [PATCH v2] t9832,t2200: avoid using pipes in git commands

On Sun, Oct 18, 2020 at 10:42 AM Amanda Shafack via GitGitGadget <gitgitgadget@gmail.com> wrote:

> t9832,t2200: avoid using pipes in git commands

The subject is a bit confusing since pipes aren't used in Git commands; instead, Git commands may be components of pipes. However, even that is too imprecise. The issue this patch is addressing is that we want to avoid Git commands _upstream_ in a pipe. It's perfectly acceptable for the Git command to be the final element of a pipe since the pipe returns the exit code of the final command. So, to be more precise, the subject could say:

    t2200,t9832: avoid using `git` upstream in a pipe
Nit: It's subjective, but it feels a bit more natural to list the test
numbers in ascending order rather than descending order, which is why
I swapped them around in the example above.
Show 5 quoted lines
> When a git command is upstream in a pipe, an unexpected failure of
> the git command will go unnoticed.
>
> Write out the output of the git command to a file, so as to actively
> catch a failure of the git command.

It's easy to see from the patch itself that the output of the Git command is now written to a file, so it's not necessary to say so in the commit message. Therefore, the entire body of the commit message could be written more succinctly, perhaps like this:

    Avoid placing `git` upstream in a pipe since doing so throws away
    its exit code, thus an unexpected failure may go unnoticed.

The actual patch itself looks fine, and these comments about the commit message are quite minor, thus there probably is no need to re-roll (though feel free to do so if you think the bit of extra polishing of the commit message is worthwhile).

Thanks.
Junio C Hamano· Oct 18, 2020, 20:04 UTC · re: Eric Sunshine · lore

Re: [PATCH v2] t9832,t2200: avoid using pipes in git commands

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 7 quoted lines
> precise, the subject could say:
>
>     t2200,t9832: avoid using `git` upstream in a pipe
>
> Nit: It's subjective, but it feels a bit more natural to list the test
> numbers in ascending order rather than descending order, which is why
> I swapped them around in the example above.
;-)
Show 13 quoted lines
>> When a git command is upstream in a pipe, an unexpected failure of
>> the git command will go unnoticed.
>>
>> Write out the output of the git command to a file, so as to actively
>> catch a failure of the git command.
>
> It's easy to see from the patch itself that the output of the Git
> command is now written to a file, so it's not necessary to say so in
> the commit message. Therefore, the entire body of the commit message
> could be written more succinctly, perhaps like this:
>
>     Avoid placing `git` upstream in a pipe since doing so throws away
>     its exit code, thus an unexpected failure may go unnoticed.
Yup.
> The actual patch itself looks fine, and these comments about the
> commit message are quite minor, thus there probably is no need to
> re-roll (though feel free to do so if you think the bit of extra
> polishing of the commit message is worthwhile).

IIUC, the microproject experience aims new contributors to get used to the style of communication that happens during review cycles of a typical topic, using a trivial dip-the-toes-in-the-water problem as an example. I'd rather not to see contributors get into the habit of leaving loose ends and have somebody else clean after them.

Thanks.
Amanda Shafack· Oct 18, 2020, 22:04 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] t9832,t2200: avoid using pipes in git commands

On Sun, Oct 18, 2020 at 9:04 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 39 quoted lines
>
> Eric Sunshine <sunshine@sunshineco.com> writes:
>
> > precise, the subject could say:
> >
> >     t2200,t9832: avoid using `git` upstream in a pipe
> >
> > Nit: It's subjective, but it feels a bit more natural to list the test
> > numbers in ascending order rather than descending order, which is why
> > I swapped them around in the example above.
>
> ;-)
>
> >> When a git command is upstream in a pipe, an unexpected failure of
> >> the git command will go unnoticed.
> >>
> >> Write out the output of the git command to a file, so as to actively
> >> catch a failure of the git command.
> >
> > It's easy to see from the patch itself that the output of the Git
> > command is now written to a file, so it's not necessary to say so in
> > the commit message. Therefore, the entire body of the commit message
> > could be written more succinctly, perhaps like this:
> >
> >     Avoid placing `git` upstream in a pipe since doing so throws away
> >     its exit code, thus an unexpected failure may go unnoticed.
>
> Yup.
>
> > The actual patch itself looks fine, and these comments about the
> > commit message are quite minor, thus there probably is no need to
> > re-roll (though feel free to do so if you think the bit of extra
> > polishing of the commit message is worthwhile).
>
> IIUC, the microproject experience aims new contributors to get used
> to the style of communication that happens during review cycles of a
> typical topic, using a trivial dip-the-toes-in-the-water problem as
> an example.  I'd rather not to see contributors get into the habit
> of leaving loose ends and have somebody else clean after them.
Taken very seriously
> Thanks.
-- 
Cheers!

Amanda  Shafack
Amanda Shafack· Oct 18, 2020, 20:40 UTC · re: Eric Sunshine · lore

Re: [PATCH v2] t9832,t2200: avoid using pipes in git commands

On Sun, Oct 18, 2020 at 8:25 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 19 quoted lines
>
> On Sun, Oct 18, 2020 at 10:42 AM Amanda Shafack via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
> > t9832,t2200: avoid using pipes in git commands
>
> The subject is a bit confusing since pipes aren't used in Git
> commands; instead, Git commands may be components of pipes. However,
> even that is too imprecise. The issue this patch is addressing is that
> we want to avoid Git commands _upstream_ in a pipe. It's perfectly
> acceptable for the Git command to be the final element of a pipe since
> the pipe returns the exit code of the final command. So, to be more
> precise, the subject could say:
>
>     t2200,t9832: avoid using `git` upstream in a pipe
>
> Nit: It's subjective, but it feels a bit more natural to list the test
> numbers in ascending order rather than descending order, which is why
> I swapped them around in the example above.
>
I agree it looks more appropriate.
Show 18 quoted lines
> > When a git command is upstream in a pipe, an unexpected failure of
> > the git command will go unnoticed.
> >
> > Write out the output of the git command to a file, so as to actively
> > catch a failure of the git command.
>
> It's easy to see from the patch itself that the output of the Git
> command is now written to a file, so it's not necessary to say so in
> the commit message. Therefore, the entire body of the commit message
> could be written more succinctly, perhaps like this:
>
>     Avoid placing `git` upstream in a pipe since doing so throws away
>     its exit code, thus an unexpected failure may go unnoticed.
>
> The actual patch itself looks fine, and these comments about the
> commit message are quite minor, thus there probably is no need to
> re-roll (though feel free to do so if you think the bit of extra
> polishing of the commit message is worthwhile).

I believe it's best practice to optimize one's work as much as possible, so I have included these changes. Thanks for the detailed explanation.

> Thanks.
-- 
Cheers!

Amanda  Shafack
Amanda Shafack via GitGitGadget· Oct 18, 2020, 20:48 UTC · re: Amanda Shafack via GitGitGadget · lore

[PATCH v3] t2200,t9832: avoid using 'git' upstream in a pipe

From: Amanda Shafack <shafack.likhene@gmail.com>

Avoid placing `git` upstream in a pipe since doing so throws away its exit code, thus an unexpected failure may go unnoticed.

Signed-off-by: Amanda Shafack <shafack.likhene@gmail.com>
---
    [Outreachy][Patch v3] t2200,t9832: avoid using 'git' upstream in a pipe
    
    Changes since v2:
    
     * Optimized commit message
    
    Signed-off-by: Amanda Shafack shafack.likhene@gmail.com
    [shafack.likhene@gmail.com]
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-885%2Flkmandy%2Favoid-pipes-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-885/lkmandy/avoid-pipes-v3
Pull-Request: https://github.com/git/git/pull/885
Range-diff vs v2:
 1:  bca393e69a ! 1:  d5f508b055 t9832,t2200: avoid using pipes in git commands
     @@ Metadata
      Author: Amanda Shafack <shafack.likhene@gmail.com>
      
       ## Commit message ##
     -    t9832,t2200: avoid using pipes in git commands
     +    t2200,t9832: avoid using 'git' upstream in a pipe
      
     -    When a git command is upstream in a pipe, an unexpected failure of
     -    the git command will go unnoticed.
     -
     -    Write out the output of the git command to a file, so as to actively
     -    catch a failure of the git command.
     +    Avoid placing `git` upstream in a pipe since doing so throws away
     +    its exit code, thus an unexpected failure may go unnoticed.
      
          Signed-off-by: Amanda Shafack <shafack.likhene@gmail.com>
      
 t/t2200-add-update.sh | 3 ++-
 t/t9832-unshelve.sh   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
Show changes to 2 files +4 −2

t/t2200-add-update.sh, t/t9832-unshelve.sh

diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
index f764b7e3f5..7cb7a70382 100755
--- a/t/t2200-add-update.sh
+++ b/t/t2200-add-update.sh
@@ -179,7 +179,8 @@ test_expect_success 'add -u resolves unmerged paths' '
 
 test_expect_success '"add -u non-existent" should fail' '
 	test_must_fail git add -u non-existent &&
-	! (git ls-files | grep "non-existent")
+	git ls-files >actual &&
+	! grep "non-existent" actual
 '
 
 test_done
diff --git a/t/t9832-unshelve.sh b/t/t9832-unshelve.sh
index 7194fb2855..6b3cb0414a 100755
--- a/t/t9832-unshelve.sh
+++ b/t/t9832-unshelve.sh
@@ -68,7 +68,8 @@ EOF
 		cd "$git" &&
 		change=$(last_shelved_change) &&
 		git p4 unshelve $change &&
-		git show refs/remotes/p4-unshelved/$change | grep -q "Further description" &&
+		git show refs/remotes/p4-unshelved/$change >actual &&
+		grep -q "Further description" actual &&
 		git cherry-pick refs/remotes/p4-unshelved/$change &&
 		test_path_is_file file2 &&
 		test_cmp file1 "$cli"/file1 &&

base-commit: a5fa49ff0a8f3252c6bff49f92b85e7683868f8a
-- 
gitgitgadget
Junio C Hamano· Oct 18, 2020, 21:01 UTC · re: Amanda Shafack via GitGitGadget · lore

Re: [PATCH v3] t2200,t9832: avoid using 'git' upstream in a pipe

"Amanda  Shafack  via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Amanda Shafack <shafack.likhene@gmail.com>
>
> Avoid placing `git` upstream in a pipe since doing so throws away
> its exit code, thus an unexpected failure may go unnoticed.
Well explained.
> Signed-off-by: Amanda Shafack <shafack.likhene@gmail.com>
> ---
Show 12 quoted lines
> diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh
> index f764b7e3f5..7cb7a70382 100755
> --- a/t/t2200-add-update.sh
> +++ b/t/t2200-add-update.sh
> @@ -179,7 +179,8 @@ test_expect_success 'add -u resolves unmerged paths' '
>  
>  test_expect_success '"add -u non-existent" should fail' '
>  	test_must_fail git add -u non-existent &&
> -	! (git ls-files | grep "non-existent")
> +	git ls-files >actual &&
> +	! grep "non-existent" actual
>  '

In the scope of this patch, the above change is a good rewrite. Let's stop the iteration here---you've demonstrated through the microproject that you can now comfortably be involved in the review discussion.

In a larger scope of "can we write this particular line better?", however, the above may not be the _best_ answer. For example,

	test_must_fail git ls-files --error-unmatch non-existent

would be another and a more direct way to ensure that the named path does not appear in the index.

Thanks.

← back to recent threads