t/t1517: automate `git subcmd -h` tests outside a repository

Replace manual `-h` tests with a loop over all subcommands using `git --list-cmds=main`. This ensures consistent coverage of `-h` behavior outside a repo and future-proofs the test by covering new commands automatically. Known exceptions are skipped or marked as expected failures. Suggested-by: Patrick Steinhardt <ps@pks.im> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: D. Ben Knoble <ben.knoble+github@gmail.com> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Usman Akinyemi committed Aug 8, 2025 at 06:36 UTC 39fc4085620b60f8a06239a249f6877111e5ac11
1 file changed +28 -2
t/t1517-outside-repo.sh
+28 -2
@@ -109,8 +109,6 @@ test_expect_success LIBCURL 'remote-http outside repository' '
109
110 test_expect_success 'update-server-info does not crash with -h' '
111 test_expect_code 129 git update-server-info -h >usage &&
112 - test_grep "[Uu]sage: git update-server-info " usage &&
113 - test_expect_code 129 nongit git update-server-info -h >usage &&
112 test_grep "[Uu]sage: git update-server-info " usage
113 '
114
@@ -121,4 +119,32 @@ test_expect_success 'prune does not crash with -h' '
119 test_grep "[Uu]sage: git prune " usage
120 '
121
122 +for cmd in $(git --list-cmds=main)
123 +do
124 + cmd=${cmd%.*} # strip .sh, .perl, etc.
125 + case "$cmd" in
126 + archimport | cvsexportcommit | cvsimport | cvsserver | daemon | \
127 + difftool--helper | filter-branch | fsck-objects | get-tar-commit-id | \
128 + http-backend | http-fetch | http-push | init-db | \
129 + merge-octopus | merge-one-file | merge-resolve | mergetool | \
130 + mktag | p4 | p4.py | pickaxe | remote-ftp | remote-ftps | \
131 + remote-http | remote-https | replay | send-email | \
132 + sh-i18n--envsubst | shell | show | stage | submodule | svn | \
133 + upload-archive--writer | upload-pack | web--browse | whatchanged)
134 + expect_outcome=expect_failure ;;
135 + *)
136 + expect_outcome=expect_success ;;
137 + esac
138 + case "$cmd" in
139 + instaweb)
140 + prereq=PERL ;;
141 + *)
142 + prereq= ;;
143 + esac
144 + test_$expect_outcome $prereq "'git $cmd -h' outside a repository" '
145 + test_expect_code 129 nongit git $cmd -h >usage &&
146 + test_grep "[Uu]sage: git $cmd " usage
147 + '
148 +done
149 +
150 test_done