Merge branch 'tj/drop-no-parseopt' into jch

The 'NO_PARSEOPT' macro has been removed from a few commands that have
migrated to use the parse_options() API, so that they will be included
in the output of 'git --list-cmds=parseopt' for shell completion, and
'git fast-import' has been updated to handle shell completion requests
without blocking on standard input.

* tj/drop-no-parseopt:
  t0012: catch builtins that keep NO_PARSEOPT after conversion
  git.c: drop NO_PARSEOPT from builtins that use parse-options
  parse-options: answer --git-completion-helper before command runs
This commit is contained in:
Junio C Hamano committed 2026-11-05 20:44:55 -08:00
commit f6f0f26564
5 files changed
+57 -4

No files matched your search

+4 -4
View File
@@ -571,11 +571,11 @@ static struct cmd_struct commands[] = {
{ "diff", cmd_diff, NO_PARSEOPT },
{ "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },
{ "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT },
{ "diff-pairs", cmd_diff_pairs, RUN_SETUP | NO_PARSEOPT },
{ "diff-pairs", cmd_diff_pairs, RUN_SETUP },
{ "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT },
{ "difftool", cmd_difftool, RUN_SETUP_GENTLY },
{ "fast-export", cmd_fast_export, RUN_SETUP },
{ "fast-import", cmd_fast_import, RUN_SETUP | NO_PARSEOPT },
{ "fast-import", cmd_fast_import, RUN_SETUP },
{ "fetch", cmd_fetch, RUN_SETUP },
{ "fetch-pack", cmd_fetch_pack, RUN_SETUP | NO_PARSEOPT },
{ "fmt-merge-msg", cmd_fmt_merge_msg, RUN_SETUP },
@@ -626,7 +626,7 @@ static struct cmd_struct commands[] = {
{ "pack-redundant", cmd_pack_redundant, RUN_SETUP | NO_PARSEOPT | DEPRECATED },
#endif
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY | NO_PARSEOPT },
{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY },
{ "pickaxe", cmd_blame, RUN_SETUP },
{ "prune", cmd_prune, RUN_SETUP },
{ "prune-packed", cmd_prune_packed, RUN_SETUP },
@@ -676,7 +676,7 @@ static struct cmd_struct commands[] = {
{ "upload-archive--writer", cmd_upload_archive_writer, NO_PARSEOPT },
{ "upload-pack", cmd_upload_pack },
{ "url-parse", cmd_url_parse },
{ "var", cmd_var, RUN_SETUP_GENTLY | NO_PARSEOPT },
{ "var", cmd_var, RUN_SETUP_GENTLY },
{ "verify-commit", cmd_verify_commit, RUN_SETUP },
{ "verify-pack", cmd_verify_pack },
{ "verify-tag", cmd_verify_tag, RUN_SETUP },
+6
View File
@@ -1745,6 +1745,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);
}
}
}
+6
View File
@@ -439,6 +439,12 @@ int parse_options_takes_argument(const struct option *opt);
NORETURN void usage_with_options(const char * const *usagestr,
const struct option *options);
/*
* Programs that call parse_options() early do not need this function.
* If your program has to answer help requests (-h and --help-all) or
* the completion helper before parse_options() runs, call this
* function to answer them.
*/
void show_usage_with_options_if_asked(int ac, const char **av,
const char * const *usage,
const struct option *options);
+25
View File
@@ -267,4 +267,29 @@ do
'
done <builtins
test_expect_success 'generate list of builtins without parse-options' '
git --list-cmds=parseopt >parseopt &&
tr " " "\n" <parseopt | sort >sorted-parseopt &&
sort builtins >sorted-builtins &&
comm -23 sorted-builtins sorted-parseopt >no-parseopt
'
while read builtin
do
case "$builtin" in
# these answer with the diff options
diff|diff-files|diff-index|diff-tree|rev-list)
continue ;;
# rev-parse prints unknown arguments back
rev-parse)
continue ;;
esac
test_expect_success "$builtin does not answer --git-completion-helper" '
test_might_fail git $builtin --git-completion-helper \
</dev/null >output 2>/dev/null &&
test_grep ! "^--" output
'
done <no-parseopt
test_done
+16
View File
@@ -2950,6 +2950,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)
###