git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] t2027: avoid using pipes

From
Prathamesh Chavan <pc44800@gmail.com>
Date
Mar 9, 2017, 08:56 UTC
Message-ID
<CAME+mvUDsBec0L9o_wpAMin-rbn-SqS1OZcuyfRw+U7b-EOXeQ@mail.gmail.com>
In-Reply-To
<CAP8UFD0GtRdjCMcbhjgA0rVaAMFtyto8JxfqbivODarBB0eK8w@mail.gmail.com>

On Thu, Mar 9, 2017 at 1:38 PM, Christian Couder <christian.couder@gmail.com> wrote:

Show 7 quoted lines
> On Wed, Mar 8, 2017 at 4:13 PM, Prathamesh Chavan <pc44800@gmail.com> wrote:
>> The exit code of the upstream of a pipe is ignored thus we should avoid
>> using it.
>
> You might want to say more specifically that we should avoid piping a
> git command into another one as this could mask a failure of the git
> command.
Yes. I will add be specific, and update my patch.
Show 24 quoted lines
>
>> By writing out the output of the git command to a file, we
>> can test the exit codes of both the commands.
>>
>> Signed-off-by: Prathamesh <pc44800@gmail.com>
>> ---
>>  t/t2027-worktree-list.sh | 14 +++++++-------
>>  1 file changed, 7 insertions(+), 7 deletions(-)
>>
>> diff --git a/t/t2027-worktree-list.sh b/t/t2027-worktree-list.sh
>> index 848da5f..daa7a04 100755
>> --- a/t/t2027-worktree-list.sh
>> +++ b/t/t2027-worktree-list.sh
>> @@ -31,7 +31,7 @@ test_expect_success '"list" all worktrees from main' '
>>         test_when_finished "rm -rf here && git worktree prune" &&
>>         git worktree add --detach here master &&
>>         echo "$(git -C here rev-parse --show-toplevel) $(git rev-parse --short HEAD) (detached HEAD)" >>expect &&
>> -       git worktree list | sed "s/  */ /g" >actual &&
>> +       git worktree list >out && sed "s/  */ /g" <out >actual &&
>
> I think it's better if the 'sed' command is on a separate line.
>
> Also you may have used just "out" instead of "<out" in the 'sed' command...
>

Actually I noticed that: $ git grep sed |grep "<" |wc -l 307

As at most places, wherever pipes aren't being used, the input to sed command is passed using "<". Hence I chose to use "<" at places specifically at places where sed was used, even after knowing that just "out" will work.

Show 18 quoted lines
>>         test_cmp expect actual
>>  '
>>
>> @@ -118,9 +118,9 @@ test_expect_success 'broken main worktree still at the top' '
>>                 cd linked &&
>>                 echo "worktree $(pwd)" >expected &&
>>                 echo "ref: .broken" >../.git/HEAD &&
>> -               git worktree list --porcelain | head -n 3 >actual &&
>> +               git worktree list --porcelain >out && head -n 3 out >actual &&
>
> ... as above you use "out" not "<out" in the 'head' command.
>
>>                 test_cmp ../expected actual &&
>> -               git worktree list | head -n 1 >actual.2 &&
>> +               git worktree list >out && head -n 1 out >actual.2 &&
>>                 grep -F "(error)" actual.2
>>         )
>>  '
Previous: Christian CouderNext: Prathamesh Chavan
Message 6 of 11 in “t2027: avoid using pipes”
  1. t2027: avoid using pipesPrathamesh Chavan, Mar 8, 2017
  2. Jon LoeligerMar 8, 2017
  3. Prathamesh ChavanMar 8, 2017
  4. Prathamesh ChavanMar 8, 2017
  5. Christian CouderMar 9, 2017
  6. Prathamesh ChavanMar 9, 2017
  7. t2027: avoid using pipesPrathamesh Chavan, Mar 9, 2017
  8. t2027: avoid using pipesPrathamesh Chavan, Mar 9, 2017
  9. Christian CouderMar 9, 2017
  10. t2027: avoid using pipesPrathamesh Chavan, Mar 9, 2017
  11. Prathamesh ChavanMar 10, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.