builtin/verify-tag: stop using `the_repository`

Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/verify-tag.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_verify_tag()` function with `repo` set to NULL and then early in the function, `parse_options()` call will give the options help and exit. Mentored-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Usman Akinyemi committed Mar 8, 2025 at 05:05 UTC 43a839197795a7f0582efd66bc249dac89f86b68
2 files changed +10 -4
builtin/verify-tag.c
+3 -4
@@ -5,7 +5,6 @@
5 *
6 * Based on git-verify-tag.sh
7 */
8 -#define USE_THE_REPOSITORY_VARIABLE
8 #include "builtin.h"
9 #include "config.h"
10 #include "gettext.h"
@@ -23,7 +22,7 @@ static const char * const verify_tag_usage[] = {
22 int cmd_verify_tag(int argc,
23 const char **argv,
24 const char *prefix,
26 - struct repository *repo UNUSED)
25 + struct repository *repo)
26 {
27 int i = 1, verbose = 0, had_error = 0;
28 unsigned flags = 0;
@@ -35,7 +34,7 @@ int cmd_verify_tag(int argc,
34 OPT_END()
35 };
36
38 - git_config(git_default_config, NULL);
37 + repo_config(repo, git_default_config, NULL);
38
39 argc = parse_options(argc, argv, prefix, verify_tag_options,
40 verify_tag_usage, PARSE_OPT_KEEP_ARGV0);
@@ -56,7 +55,7 @@ int cmd_verify_tag(int argc,
55 struct object_id oid;
56 const char *name = argv[i++];
57
59 - if (repo_get_oid(the_repository, name, &oid)) {
58 + if (repo_get_oid(repo, name, &oid)) {
59 had_error = !!error("tag '%s' not found.", name);
60 continue;
61 }
t/t7030-verify-tag.sh
+7
@@ -7,6 +7,13 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY/lib-gpg.sh"
9
10 +test_expect_success GPG 'verify-tag does not crash with -h' '
11 + test_expect_code 129 git verify-tag -h >usage &&
12 + test_grep "[Uu]sage: git verify-tag " usage &&
13 + test_expect_code 129 nongit git verify-tag -h >usage &&
14 + test_grep "[Uu]sage: git verify-tag " usage
15 +'
16 +
17 test_expect_success GPG 'create signed tags' '
18 echo 1 >file && git add file &&
19 test_tick && git commit -m initial &&