From: Tanga Joris <tangajoris@gmail.com>
To: git@vger.kernel.org
Cc: l.s.r@web.de, gitster@pobox.com, christian.couder@gmail.com,
siddharthasthana31@gmail.com, kaartic.sivaraam@gmail.com,
usmanakinyemi202@gmail.com, herroyalpriestess@gmail.com,
Tanga Joris <tangajoris@gmail.com>
Subject: [Outreachy PATCH v4 1/3] parse-options: answer --git-completion-helper before command runs
Date: Thu, 5 Nov 2026 03:39:11 +0300 [thread overview]
Message-ID: <20261105003914.708836-1-tangajoris@gmail.com> (raw)
In-Reply-To: <20261029231621.48958-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. The next
commit removes the NO_PARSEOPT flag from fast-import, which would make
"git fast-import --<TAB>" freeze without this patch.
show_usage_with_options_if_asked() already answers -h and --help-all
before a command does any work. Teach it to answer the completion
helper too. Then fast-import, and the 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>
Helped-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
Helped-by: Cynthia Uche <herroyalpriestess@gmail.com>
Signed-off-by: Tanga Joris <tangajoris@gmail.com>
---
Changes since v3:
- Added a sentence to the log message saying that the next commit
removes NO_PARSEOPT from fast-import, as Kaartic suggested.
- Added a comment above show_usage_with_options_if_asked() in
parse-options.h, as Kaartic suggested.
- Added Cynthia's test for --git-completion-helper-all. I also added
the tmp_pack_* check from the first test to it, because without
it the test still passes when the fix is reverted.
- 2/3 is unchanged.
- 3/3 is new, it adds the test Kaartic suggested.
parse-options.c | 6 ++++++
parse-options.h | 6 ++++++
t/t9300-fast-import.sh | 16 ++++++++++++++++
3 files changed, 28 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/parse-options.h b/parse-options.h
index f68b51ceca..7ad33801fe 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -427,6 +427,12 @@ int parse_options(int argc, const char **argv, const char *prefix,
NORETURN void usage_with_options(const char * const *usagestr,
const struct option *options);
+/*
+ * If the only argument is -h, --help-all, --git-completion-helper or
+ * --git-completion-helper-all, print the answer and exit. Call this
+ * before the command does any work. Then asking for help or for the
+ * completion list does not wait for input or leave files behind.
+ */
void show_usage_with_options_if_asked(int ac, const char **av,
const char * const *usage,
const struct option *options);
diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh
index 73c6e3d448..1305614381 100755
--- a/t/t9300-fast-import.sh
+++ b/t/t9300-fast-import.sh
@@ -2914,6 +2914,22 @@ 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
+'
+
+test_expect_success 'R: --git-completion-helper-all does not read from stdin' '
+ find .git/objects/pack -name "tmp_pack_*" >before &&
+ echo garbage | git fast-import --git-completion-helper-all >all &&
+ test_grep -e "--allow-unsafe-features" all &&
+ find .git/objects/pack -name "tmp_pack_*" >after &&
+ test_cmp before after
+'
+
###
### series S (mark and path parsing)
###
--
2.43.0
next prev parent reply other threads:[~2026-11-05 0:39 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-24 5:24 [Outreachy PATCH] git.c: drop NO_PARSEOPT from builtins that use parse-options Tanga Joris
2026-10-25 7:59 ` René Scharfe
2026-10-26 2:59 ` Tanga Joris
2026-10-26 4:58 ` Junio C Hamano
2026-10-29 1:26 ` [Outreachy PATCH v2 1/2] fast-import: handle --git-completion-helper before reading input Tanga Joris
2026-10-29 1:26 ` [Outreachy PATCH v2 2/2] git.c: drop NO_PARSEOPT from builtins that use parse-options Tanga Joris
2026-10-29 18:04 ` [Outreachy PATCH v2 1/2] fast-import: handle --git-completion-helper before reading input Junio C Hamano
2026-10-29 23:16 ` [Outreachy PATCH v3 1/2] parse-options: answer --git-completion-helper before command runs Tanga Joris
2026-10-29 23:16 ` [Outreachy PATCH v3 2/2] git.c: drop NO_PARSEOPT from builtins that use parse-options Tanga Joris
2026-10-30 10:21 ` Kaartic Sivaraam
2026-11-02 2:26 ` Tanga Joris
2026-10-30 9:44 ` [Outreachy PATCH v3 1/2] parse-options: answer --git-completion-helper before command runs Kaartic Sivaraam
2026-10-31 22:01 ` Tanga Joris
2026-11-03 9:25 ` Cynthia Uche
2026-11-04 22:34 ` Tanga Joris
2026-11-05 0:39 ` Tanga Joris [this message]
2026-11-05 0:39 ` [Outreachy PATCH v4 2/3] git.c: drop NO_PARSEOPT from builtins that use parse-options Tanga Joris
2026-11-05 0:39 ` [Outreachy PATCH v4 3/3] t0012: catch builtins that keep NO_PARSEOPT after conversion Tanga Joris
2026-11-05 15:32 ` [Outreachy PATCH v4 1/3] parse-options: answer --git-completion-helper before command runs Junio C Hamano
2026-11-05 19:14 ` Tanga Joris
2026-11-05 22:34 ` [Outreachy PATCH v5 " Tanga Joris
2026-11-05 22:34 ` [Outreachy PATCH v5 2/3] git.c: drop NO_PARSEOPT from builtins that use parse-options Tanga Joris
2026-11-05 22:34 ` [Outreachy PATCH v5 3/3] t0012: catch builtins that keep NO_PARSEOPT after conversion Tanga Joris
2026-11-06 4:11 ` [Outreachy PATCH v5 1/3] parse-options: answer --git-completion-helper before command runs Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261105003914.708836-1-tangajoris@gmail.com \
--to=tangajoris@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=herroyalpriestess@gmail.com \
--cc=kaartic.sivaraam@gmail.com \
--cc=l.s.r@web.de \
--cc=siddharthasthana31@gmail.com \
--cc=usmanakinyemi202@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.