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

Re: [PATCH v5 2/2] hooks: allow input from stdin for commit-related hooks

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 9, 2020, 22:37 UTC
Message-ID
<xmqq360e1u9a.fsf@gitster.c.googlers.com>
In-Reply-To
<25db4da3cd5fc7e81141078261086c392541c5d1.1607544408.git.gitgitgadget@gmail.com>
"Orgad Shaneh via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> It's important to note that the hook author should be aware that stdin
> is not always applicable. For example, when running from IDE. This can
> be checked by isatty on stdin. The hooks should handle cases of closed
> input, and possibly fall-back to GUI input, or have sane defaults with
> a message to the user on this case.

I think this point was already brought up in the review on previous rounds, but when the hook needs to check the standard input anyway, it probably is a better design to close and have the hook open tty if needed, isn't it? I do not recall I saw a satisfactory answer to that question.

Show 7 quoted lines
> Allow stdin only for commit-related hooks. Some of the other hooks pass
> their own input to the hook, so don't change them.
>
> Note: If pre-commit reads from stdin, and git commit is executed with
> -F - (read message from stdin), stdin cannot be passed to the hook,
> since it will consume it before reaching the point where it is read for
> the commit message.

It is unclear what that Note is trying to achieve. Is it describing a known-bug in this implementation (if so, we'd probably need to update the documentation to mention this known regression)? Is it describing a reason why certain part of patch was done in a certain way that is not described in this message (e.g. when -F option is in effect the standard input stream is closed when invoking a hook)?

Thanks.
Previous: Orgad Shaneh via GitGitGadget
Message 22 of 22 in “hooks: allow input from stdin”
  1. hooks: allow input from stdinOrgad Shaneh via GitGitGadget, Nov 17, 2020
  2. Junio C HamanoNov 17, 2020
  3. hooks: allow input from stdinOrgad Shaneh via GitGitGadget, Nov 19, 2020
  4. hooks: allow input from stdin for commit-related hooksOrgad Shaneh via GitGitGadget, Nov 19, 2020
  5. Junio C HamanoNov 19, 2020
  6. Orgad ShanehNov 19, 2020
  7. 0/2 hooks: allow input from stdin for commit-related hooksOrgad Shaneh via GitGitGadget, Nov 19, 2020
  8. 2/2 commit: fix stdin conflict between message and hookOrgad Shaneh via GitGitGadget, Nov 19, 2020
  9. 1/2 hooks: allow input from stdin for commit-related hooksOrgad Shaneh via GitGitGadget, Nov 19, 2020
  10. Eric SunshineNov 19, 2020
  11. Junio C HamanoNov 19, 2020
  12. Orgad ShanehNov 20, 2020
  13. Eric SunshineNov 20, 2020
  14. Eric SunshineNov 20, 2020
  15. Orgad ShanehNov 20, 2020
  16. Junio C HamanoNov 20, 2020
  17. Ævar Arnfjörð BjarmasonNov 20, 2020
  18. Orgad ShanehNov 20, 2020
  19. 0/2 hooks: allow input from stdin for commit-related hooksOrgad Shaneh via GitGitGadget, Dec 9, 2020
  20. 1/2 hooks: lay foundations for passing stdin to hooksOrgad Shaneh via GitGitGadget, Dec 9, 2020
  21. 2/2 hooks: allow input from stdin for commit-related hooksOrgad Shaneh via GitGitGadget, Dec 9, 2020
  22. Junio C HamanoDec 9, 2020

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.