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

Re: [PATCH v2 0/3] nd/clear-gitenv-upon-use-of-alias

From
Jeff King <peff@peff.net>
Date
Dec 23, 2015, 21:31 UTC
Message-ID
<20151223213140.GB21277@sigill.intra.peff.net>
In-Reply-To
<567B05F0.5020604@kdbg.org>
On Wed, Dec 23, 2015 at 09:37:04PM +0100, Johannes Sixt wrote:
Show 11 quoted lines
> >--- a/git.c
> >+++ b/git.c
> >@@ -252,7 +252,7 @@ static int handle_alias(int *argcp, const char ***argv)
> >  			alias_argv[argc] = NULL;
> >
> >  			ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
> >-			if (ret >= 0)   /* normal exit */
> >+			if (ret != -1)  /* normal exit */
> 
> Why does this make a difference? We only ever return -1, zero, or a positive
> value from run_command/finish_command/wait_or_whine, as far as I can see.

Yeah, you're right. This bit predates 709ca73 (run-command: encode signal death as a positive integer, 2013-01-05), which came out of the same discussion. So I'd agree this hunk can simply be dropped.

That leaves the ignoring of SIGPIPE in wait_or_whine. I started to rewrite the commit message to drop the first hunk, but I found I couldn't replicate the problem in the second either!

Doing:
  GIT_PAGER=false git -c alias.foo='!git log -p' foo

doesn't trigger it. We run the alias through a shell, so we see only the munged "141" value from the shell's exit code.

Something like:
  GIT_PAGER=false git -p -c alias.foo='!yes' foo

does generate the error message. But we've redirected stderr into the pager at that point, so by definition it can never be shown.

So I think we would need a case where:
  - the outer git doesn't run the pager that dies; instead the pager is
    run inside the alias. But...
  - inside the alias cannot be a shell pipeline, since "foo | less" will
    report the exit code of "less", not "foo" (we make special arrangements
    in git to propagate the exit code of "foo"). So it pretty much has
    to be a git invocation inside the alias. But...
  - The git invocation will convert signal death in the sub-process into
    141, like a shell would.
So I'm not sure if this is triggerable at all with an alias.
I did manage to trigger it with an external command, like:
  $ cat $(which git-yes)
  #!/bin/sh
  # This _has_ to be exec, otherwise the shell converts SIGPIPE death
  # into 141.
  exec yes
and then if you run your _own_ pager, like this:
  $ git yes | false
  error: git-yes died of signal 13
you see it. But if git starts the pager, you don't:
  $ GIT_PAGER=false git -p yes

Because the stderr of the outer git process is going to the same dead pipe.

So my takeaways are:
  1. Complaining about signal death in general is going to be flaky,
     because it's so easy for shells or git to rewrite the exit code and
     not trigger WIFSIGNALED() in the first place.
  2. I doubt anybody is actually seeing this in practice anymore. But
     maybe I am misunderstanding something in Duy's series that changes
     this.
-Peff
Previous: Johannes SixtNext: Duy Nguyen
Message 31 of 39 in “Fwd: Git clone fails during pre-commit hook due to GIT_WORK_TREE=. (regression 2.5 -> 2.6)”
  1. Anthony SottileNov 24, 2015
  2. Stefan BellerNov 24, 2015
  3. Duy NguyenNov 25, 2015
  4. Duy NguyenNov 30, 2015
  5. Junio C HamanoNov 30, 2015
  6. Duy NguyenDec 1, 2015
  7. Junio C HamanoDec 2, 2015
  8. 1/2 git.c: make it clear save_env() is for alias handling onlyNguyễn Thái Ngọc Duy, Dec 3, 2015
  9. 2/2 setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when ..Nguyễn Thái Ngọc Duy, Dec 3, 2015
  10. Junio C HamanoDec 4, 2015
  11. Duy NguyenDec 5, 2015
  12. 3/2 git.c: make sure we do not leak GIT_* to alias scriptsNguyễn Thái Ngọc Duy, Dec 5, 2015
  13. Junio C HamanoDec 7, 2015
  14. Duy NguyenDec 8, 2015
  15. Jeff KingDec 8, 2015
  16. Junio C HamanoDec 8, 2015
  17. Duy NguyenDec 5, 2015
  18. Junio C HamanoDec 7, 2015
  19. 0/3 nd/clear-gitenv-upon-use-of-aliasNguyễn Thái Ngọc Duy, Dec 20, 2015
  20. 1/3 git.c: make it clear save_env() is for alias handling onlyNguyễn Thái Ngọc Duy, Dec 20, 2015
  21. 2/3 setup.c: re-fix d95138e (setup: set env $GIT_WORK_TREE when ..Nguyễn Thái Ngọc Duy, Dec 20, 2015
  22. 3/3 git.c: make sure we do not leak GIT_* to alias scriptsNguyễn Thái Ngọc Duy, Dec 20, 2015
  23. Junio C HamanoDec 21, 2015
  24. Duy NguyenDec 22, 2015
  25. Duy NguyenDec 22, 2015
  26. Junio C HamanoDec 22, 2015
  27. Jeff KingDec 23, 2015
  28. Duy NguyenDec 23, 2015
  29. Eric SunshineDec 23, 2015
  30. Johannes SixtDec 23, 2015
  31. Jeff KingDec 23, 2015
  32. Duy NguyenDec 24, 2015
  33. Jeff KingDec 29, 2015
  34. Junio C HamanoDec 29, 2015
  35. Revert "setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR"Nguyễn Thái Ngọc Duy, Dec 21, 2015
  36. Junio C HamanoDec 21, 2015
  37. Junio C HamanoDec 21, 2015
  38. Duy NguyenDec 22, 2015
  39. Junio C HamanoDec 22, 2015

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.