]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/t1517: automate `git subcmd -h` tests outside a repository
authorUsman Akinyemi <usmanakinyemi202@gmail.com>
Fri, 8 Aug 2025 01:06:49 +0000 (06:36 +0530)
committerJunio C Hamano <gitster@pobox.com>
Fri, 8 Aug 2025 14:48:27 +0000 (07:48 -0700)
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>
t/t1517-outside-repo.sh

index 8f59b867f2701ff14a5aeca97e64b641d91e5e6e..e9f6d03e1bc948cec0fc7561355a0df5821c4b69 100755 (executable)
@@ -109,8 +109,6 @@ test_expect_success LIBCURL 'remote-http outside repository' '
 
 test_expect_success 'update-server-info does not crash with -h' '
        test_expect_code 129 git update-server-info -h >usage &&
-       test_grep "[Uu]sage: git update-server-info " usage &&
-       test_expect_code 129 nongit git update-server-info -h >usage &&
        test_grep "[Uu]sage: git update-server-info " usage
 '
 
@@ -121,4 +119,32 @@ test_expect_success 'prune does not crash with -h' '
        test_grep "[Uu]sage: git prune " usage
 '
 
+for cmd in $(git --list-cmds=main)
+do
+       cmd=${cmd%.*} # strip .sh, .perl, etc.
+       case "$cmd" in
+       archimport | cvsexportcommit | cvsimport | cvsserver | daemon | \
+       difftool--helper | filter-branch | fsck-objects | get-tar-commit-id | \
+       http-backend | http-fetch | http-push | init-db | \
+       merge-octopus | merge-one-file | merge-resolve | mergetool | \
+       mktag | p4 | p4.py | pickaxe | remote-ftp | remote-ftps | \
+       remote-http | remote-https | replay | send-email | \
+       sh-i18n--envsubst | shell | show | stage | submodule | svn | \
+       upload-archive--writer | upload-pack | web--browse | whatchanged)
+               expect_outcome=expect_failure ;;
+       *)
+               expect_outcome=expect_success ;;
+       esac
+       case "$cmd" in
+       instaweb)
+               prereq=PERL ;;
+       *)
+               prereq= ;;
+       esac
+       test_$expect_outcome $prereq "'git $cmd -h' outside a repository" '
+               test_expect_code 129 nongit git $cmd -h >usage &&
+               test_grep "[Uu]sage: git $cmd " usage
+       '
+done
+
 test_done