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

[Outreachy PATCH v3 1/2] parse-options: answer --git-completion-helper before command runs

From
TJTanga Joris <tangajoris@gmail.com>
Date
Oct 29, 2026, 23:16 UTC
Message-ID
<20261029231621.48958-1-tangajoris@gmail.com>
In-Reply-To
<20261029012616.139783-1-tangajoris@gmail.com>

fast-import parses its options only after reading the "feature" lines from its input, and it creates a temporary pack file before that. So "git fast-import --git-completion-helper" waits for input, and each run leaves a tmp_pack_* file behind.

bash completion runs the helper with the terminal as input, so "git fast-import --<TAB>" would freeze once fast-import is no longer marked with the NO_PARSEOPT flag.

Since show_usage_with_options_if_asked() already answers -h and --help-all before a command does any work, it now also answers the completion helper, so fast-import and other commands that call it reply without reading input.

Reported-by: René Scharfe <l.s.r@web.de>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Tanga Joris <tangajoris@gmail.com>
---
Changes since v2:
 - Moved the check from fast-import into
   show_usage_with_options_if_asked() in parse-options,
   as Junio suggested.
 - 2/2 is unchanged
 parse-options.c        | 6 ++++++
 t/t9300-fast-import.sh | 8 ++++++++
 2 files changed, 14 insertions(+)
diff --git a/parse-options.c b/parse-options.c
index 283a0f1dc2..f2a23b79a4 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -1536,6 +1536,12 @@ void show_usage_with_options_if_asked(int ac, const char **av,
 			usage_with_options_internal(NULL, usagestr, opts,
 						    USAGE_FULL, USAGE_TO_STDOUT);
 			exit(0);
+		} else if (!strcmp(av[1], "--git-completion-helper")) {
+			show_gitcomp(opts, 0);
+			exit(0);
+		} else if (!strcmp(av[1], "--git-completion-helper-all")) {
+			show_gitcomp(opts, 1);
+			exit(0);
 		}
 	}
 }
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 73c6e3d448..99d7843217 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -2914,6 +2914,14 @@ test_expect_success 'R: blob appears only once' '
 	test 1 = $n
 '
 
+test_expect_success 'R: --git-completion-helper does not read from stdin' '
+	find .git/objects/pack -name "tmp_pack_*" >before &&
+	echo garbage | git fast-import --git-completion-helper >out &&
+	test_grep -e "--date-format=" out &&
+	find .git/objects/pack -name "tmp_pack_*" >after &&
+	test_cmp before after
+'
+
 ###
 ### series S (mark and path parsing)
 ###
-- 
2.43.0
Previous: Junio C HamanoNext: Tanga Joris
Message 8 of 13 in “git.c: drop NO_PARSEOPT from builtins that use parse-options”
  1. git.c: drop NO_PARSEOPT from builtins that use parse-optionsTanga Joris, Oct 24, 2026
  2. René ScharfeOct 25, 2026
  3. Tanga JorisOct 26, 2026
  4. Junio C HamanoOct 26, 2026
  5. 1/2 fast-import: handle --git-completion-helper before reading inputTanga Joris, Oct 29, 2026
  6. 2/2 git.c: drop NO_PARSEOPT from builtins that use parse-optionsTanga Joris, Oct 29, 2026
  7. Junio C HamanoOct 29, 2026
  8. 1/2 parse-options: answer --git-completion-helper before command runsTanga Joris, Oct 29, 2026
  9. 2/2 git.c: drop NO_PARSEOPT from builtins that use parse-optionsTanga Joris, Oct 29, 2026
  10. Kaartic SivaraamOct 30, 2026
  11. Tanga JorisNov 2, 2026
  12. Kaartic SivaraamOct 30, 2026
  13. Tanga JorisOct 31, 2026

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.