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

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

From
Orgad Shaneh <orgads@gmail.com>
Date
Nov 20, 2020, 07:16 UTC
Message-ID
<CAGHpTB+2SV_GZT9QBSOQLYCO4znBCToCRJ5-guWMxxuQD+aA-w@mail.gmail.com>
In-Reply-To
<CAPig+cTaV-L_m3OFw=WAUKaiLqSVvhP7fjjFbE13QStibVmRjw@mail.gmail.com>
On Fri, Nov 20, 2020 at 8:49 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 24 quoted lines
>
> On Fri, Nov 20, 2020 at 1:38 AM Eric Sunshine <sunshine@sunshineco.com> wrote:
> > I do find it quite concerning that the way this series handles the
> > stdin conflict between the hook and `-F -` can break the hook silently
> > and mysteriously. How confusing for a user to write a hook which works
> > with `git commit -m msg` and `git commit -F file` but breaks silently
> > with `git commit -F -`. What is worse is that this breakage may be
> > outside the user's control. For instance, it is easy to imagine some
> > IDE passing the commit message to git-commit via stdin (using `-F -`)
> > rather than via a file (using `-F file`).
> >
> > At the very least, this change deserves a documentation update, both
> > to explain that the prepare-commit-msg hook has a valid stdin, and
> > (importantly) that it won't be able to rely upon stdin in conjunction
> > with `-F -`.
>
> What I forgot to say here was that this patch series doesn't help
> users at all if their IDE passes the commit message to git-commit via
> stdin using `-F -`. In such a case, their hook will _never_ see a
> valid stdin coming from Git, no matter what their script does. So, the
> change made by this patch series may help some users but not others,
> and this is a limitation that should be stated in the commit message
> (and perhaps mentioned in the documentation, though that may be
> difficult to do in a general way).

At least in my case, I never expect stdin to be available when running in the IDE, so my hook is expected to use GUI anyway. I only need stdin when the user is running git from the terminal. So all I need from the IDE is that it doesn't pretend to be a tty while running Git.

And regarding the hook itself - the hook author should be aware that stdin is not always a tty, and sometimes can be closed or pipe, and write the hook in a way that handles special cases.

- Orgad
Previous: Eric SunshineNext: Junio C Hamano
Message 15 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.