Re: git fails with a broken pipe when one quits the pager

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 2021-01-31 21:49:49 +0100, Ævar Arnfjörð Bjarmason wrote:
> On Sun, Jan 31 2021, Vincent Lefevre wrote:
> > FYI, I already have the exit status already in my prompt (the above
> > commands were just for the example). Still, the git behavior is
> > disturbing.
> >
> > Moreover, this doesn't solve the issue when doing something like
> >
> >   git log && some_other_command
> 
> What issue? That we're returning an exit code per getting a SIGHUP here
> is a feature. Consider:
> 
>     git -c core.pager=/bin/false log && echo showed you the output

If the pager exists with a non-zero exit status, it is normal to
return a non-zero exit status. This was not the bug I reported.

> > No! I want to be warned about real SIGPIPEs.
> 
> Not being able to write "git log" output is a real SIGPIPE.

Which is not the case here, because the full output has never been
requested by the user.

> Is it because in your mind it's got something to do with the "|" shell
> piping construct? The SIGPIPE is sent by the kernel, so it's no less
> expected in cases like:
> 
>     git log && echo foo
> 
> Than:
> 
>     git log | cat

See the difference (without the patch) between

$ git log && echo foo; echo $?
141

and

$ git log | head; echo $?
[...]
0

[...]
> Maybe we have users who'd like to work around zsh's "setopt
> PRINT_EXIT_VALUE" mode (would you want this patch if you could make zsh
> ignore 141?).

zsh is working as expected, and as I've already said, I ***WANT***
SIGPIPE to be reported by the shell, as it may indicate a real failure
in a script. BTW, I even have a script using git that relies on that:

{ git rev-list --author "$@[-1]" HEAD &&
  git rev-list --grep   "$@[-1]" HEAD } | \
  git "${@[1,-2]:-lv}" --no-walk --stdin

return $((pipestatus[2] ? pipestatus[2] : pipestatus[1]))

Here it is important not to lose any information. No pager is
involved, the full output is needed. If for some reason, the
LHS of the pipe fails due to a SIGPIPE but the right hand side
succeeds, the error will be reported.

The fact is that with a pager, the SIGPIPE with a pager is normal.
Thus with a pager, git is reporting a spurious SIGPIPE, and this
is disturbing.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux