From 39fc4085620b60f8a06239a249f6877111e5ac11 Mon Sep 17 00:00:00 2001 From: Usman Akinyemi Date: Fri, 8 Aug 2025 06:36:49 +0530 Subject: [PATCH 1/3] 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 Helped-by: Junio C Hamano Helped-by: D. Ben Knoble Signed-off-by: Usman Akinyemi Signed-off-by: Junio C Hamano --- t/t1517-outside-repo.sh | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh index 8f59b867f2..e9f6d03e1b 100755 --- a/t/t1517-outside-repo.sh +++ b/t/t1517-outside-repo.sh @@ -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 From 18aae638cbb7e6fe148b879c5b4e5ad4e5cc006d Mon Sep 17 00:00:00 2001 From: Usman Akinyemi Date: Fri, 8 Aug 2025 06:36:50 +0530 Subject: [PATCH 2/3] t5200: move `update-server-info -h` test from t1517 t1517 is now focused on testing subcommands outside a repository. Move the in-repo `-h` test for `update-server-info` to t5200, which covers this command. Suggested-by: Patrick Steinhardt Helped-by: Junio C Hamano Signed-off-by: Usman Akinyemi Signed-off-by: Junio C Hamano --- t/t1517-outside-repo.sh | 5 ----- t/t5200-update-server-info.sh | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh index e9f6d03e1b..4eba3f486d 100755 --- a/t/t1517-outside-repo.sh +++ b/t/t1517-outside-repo.sh @@ -107,11 +107,6 @@ test_expect_success LIBCURL 'remote-http outside repository' ' test_grep "^error: remote-curl" actual ' -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_success 'prune does not crash with -h' ' test_expect_code 129 git prune -h >usage && test_grep "[Uu]sage: git prune " usage && diff --git a/t/t5200-update-server-info.sh b/t/t5200-update-server-info.sh index 8365907055..a551e955b5 100755 --- a/t/t5200-update-server-info.sh +++ b/t/t5200-update-server-info.sh @@ -46,4 +46,9 @@ test_expect_success 'midx does not create duplicate pack entries' ' test_must_be_empty dups ' +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_done From 529a60a885c1f65ff0870f6d69915dd9d02d7ee9 Mon Sep 17 00:00:00 2001 From: Usman Akinyemi Date: Fri, 8 Aug 2025 06:36:51 +0530 Subject: [PATCH 3/3] t5304: move `prune -h` test from t1517 t1517 is now focused on testing subcommands outside a repository. Move the in-repo `-h` test for `prune` to t5304, which covers this command. Suggested-by: Patrick Steinhardt Signed-off-by: Usman Akinyemi Signed-off-by: Junio C Hamano --- t/t1517-outside-repo.sh | 7 ------- t/t5304-prune.sh | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/t/t1517-outside-repo.sh b/t/t1517-outside-repo.sh index 4eba3f486d..3dc602872a 100755 --- a/t/t1517-outside-repo.sh +++ b/t/t1517-outside-repo.sh @@ -107,13 +107,6 @@ test_expect_success LIBCURL 'remote-http outside repository' ' test_grep "^error: remote-curl" actual ' -test_expect_success 'prune does not crash with -h' ' - test_expect_code 129 git prune -h >usage && - test_grep "[Uu]sage: git prune " usage && - test_expect_code 129 nongit git prune -h >usage && - test_grep "[Uu]sage: git prune " usage -' - for cmd in $(git --list-cmds=main) do cmd=${cmd%.*} # strip .sh, .perl, etc. diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index 1f1f664871..2be7cd30de 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -364,4 +364,9 @@ test_expect_success 'gc.recentObjectsHook' ' git cat-file -p $BLOB ' +test_expect_success 'prune does not crash with -h' ' + test_expect_code 129 git prune -h >usage && + test_grep "[Uu]sage: git prune " usage +' + test_done