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

[PATCH] hooks: allow input from stdin

From
Orgad Shaneh via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 17, 2020, 15:02 UTC
Message-ID
<pull.790.git.1605625363309.gitgitgadget@gmail.com>
From: Orgad Shaneh <orgads@gmail.com>
Let hooks receive user input if applicable.

Closing stdin originates in f5bbc3225 (Port git commit to C, 2007). Looks like the original shell implementation did have stdin open. Not clear why the author chose to close it on the C port (maybe copy&paste).

The only hook that passes internal information to the hook via stdin is pre-push, which has its own logic.

Some references of users requesting this feature. Some of them use acrobatics to gain access to stdin: [1] https://stackoverflow.com/q/1067874/764870 [2] https://stackoverflow.com/q/47477766/764870 [3] https://stackoverflow.com/q/3417896/764870 [4] https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/3165 [5] https://github.com/typicode/husky/issues/442

Signed-off-by: Orgad Shaneh <orgads@gmail.com>
---
    hooks: allow input from stdin
    
    Let hooks receive user input if applicable.
    
    Closing stdin originates in f5bbc3225 (Port git commit to C, 2007).
    Looks like the original shell implementation did have stdin open. Not
    clear why the author chose to close it on the C port (maybe copy&paste).
    
    The only hook that passes internal information to the hook via stdin is
    pre-push, which has its own logic.
    
    Some references of users requesting this feature. Some of them use
    acrobatics to gain access to stdin: [1] 
    https://stackoverflow.com/q/1067874/764870[2] 
    https://stackoverflow.com/q/47477766/764870[3] 
    https://stackoverflow.com/q/3417896/764870[4] 
    https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/3165[5] 
    https://github.com/typicode/husky/issues/442
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-790%2Forgads%2Fhooks-stdin-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-790/orgads/hooks-stdin-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/790
 run-command.c | 1 -
 1 file changed, 1 deletion(-)
diff --git a/run-command.c b/run-command.c
index 2ee59acdc8..a17b613216 100644
--- a/run-command.c
+++ b/run-command.c
@@ -1356,7 +1356,6 @@ int run_hook_ve(const char *const *env, const char *name, va_list args)
 	while ((p = va_arg(args, const char *)))
 		strvec_push(&hook.args, p);
 	hook.env = env;
-	hook.no_stdin = 1;
 	hook.stdout_to_stderr = 1;
 	hook.trace2_hook_name = name;
 

base-commit: e31aba42fb12bdeb0f850829e008e1e3f43af500
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 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.