Skip to content

Commit 1c14b1a

Browse files
Unique-Usmangitster
authored andcommitted
builtin/send-pack: stop using the_repository
Remove the_repository global variable in favor of the repository argument that gets passed in "builtin/send-pack.c". When `-h` is passed to the command outside a Git repository, the `run_builtin()` will call the `cmd_send_pack()` 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 <[email protected]> Signed-off-by: Usman Akinyemi <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db58d5a commit 1c14b1a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

builtin/send-pack.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
21
#include "builtin.h"
32
#include "config.h"
43
#include "hex.h"
@@ -151,7 +150,7 @@ static int send_pack_config(const char *k, const char *v,
151150
int cmd_send_pack(int argc,
152151
const char **argv,
153152
const char *prefix,
154-
struct repository *repo UNUSED)
153+
struct repository *repo)
155154
{
156155
struct refspec rs = REFSPEC_INIT_PUSH;
157156
const char *remote_name = NULL;
@@ -212,7 +211,7 @@ int cmd_send_pack(int argc,
212211
OPT_END()
213212
};
214213

215-
git_config(send_pack_config, NULL);
214+
repo_config(repo, send_pack_config, NULL);
216215
argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0);
217216
if (argc > 0) {
218217
dest = argv[0];
@@ -317,7 +316,7 @@ int cmd_send_pack(int argc,
317316
set_ref_status_for_push(remote_refs, args.send_mirror,
318317
args.force_update);
319318

320-
ret = send_pack(the_repository, &args, fd, conn, remote_refs, &extra_have);
319+
ret = send_pack(repo, &args, fd, conn, remote_refs, &extra_have);
321320

322321
if (helper_status)
323322
print_helper_status(remote_refs);

t/t5400-send-pack.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ test_expect_success setup '
5555
echo Rebase &&
5656
git log'
5757

58+
test_expect_success 'send-pack does not crash with -h' '
59+
test_expect_code 129 git send-pack -h >usage &&
60+
test_grep "[Uu]sage: git send-pack " usage &&
61+
test_expect_code 129 nongit git send-pack -h >usage &&
62+
test_grep "[Uu]sage: git send-pack " usage
63+
'
64+
5865
test_expect_success 'pack the source repository' '
5966
git repack -a -d &&
6067
git prune

0 commit comments

Comments
 (0)