Skip to content

Commit c5973cb

Browse files
committed
Merge branch 'js/short-help-outside-repo-fix'
"git cmd -h" outside a repository should error out cleanly for many commands, but instead it hit a BUG(), which has been corrected. * js/short-help-outside-repo-fix: t0012: verify that built-ins handle `-h` even without gitdir checkout/fetch/pull/pack-objects: allow `-h` outside a repository
2 parents 9b7e531 + 87ad07d commit c5973cb

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

builtin/checkout.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,9 +1608,10 @@ static int checkout_main(int argc, const char **argv, const char *prefix,
16081608
opts->show_progress = -1;
16091609

16101610
git_config(git_checkout_config, opts);
1611-
1612-
prepare_repo_settings(the_repository);
1613-
the_repository->settings.command_requires_full_index = 0;
1611+
if (the_repository->gitdir) {
1612+
prepare_repo_settings(the_repository);
1613+
the_repository->settings.command_requires_full_index = 0;
1614+
}
16141615

16151616
opts->track = BRANCH_TRACK_UNSPECIFIED;
16161617

builtin/fetch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,8 +2017,10 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
20172017
}
20182018

20192019
git_config(git_fetch_config, NULL);
2020-
prepare_repo_settings(the_repository);
2021-
the_repository->settings.command_requires_full_index = 0;
2020+
if (the_repository->gitdir) {
2021+
prepare_repo_settings(the_repository);
2022+
the_repository->settings.command_requires_full_index = 0;
2023+
}
20222024

20232025
argc = parse_options(argc, argv, prefix,
20242026
builtin_fetch_options, builtin_fetch_usage, 0);

builtin/pack-objects.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3976,9 +3976,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
39763976
read_replace_refs = 0;
39773977

39783978
sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1);
3979-
prepare_repo_settings(the_repository);
3980-
if (sparse < 0)
3981-
sparse = the_repository->settings.pack_use_sparse;
3979+
if (the_repository->gitdir) {
3980+
prepare_repo_settings(the_repository);
3981+
if (sparse < 0)
3982+
sparse = the_repository->settings.pack_use_sparse;
3983+
}
39823984

39833985
reset_pack_idx_option(&pack_idx_opts);
39843986
git_config(git_pack_config, NULL);

builtin/pull.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,10 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
994994
set_reflog_message(argc, argv);
995995

996996
git_config(git_pull_config, NULL);
997-
prepare_repo_settings(the_repository);
998-
the_repository->settings.command_requires_full_index = 0;
997+
if (the_repository->gitdir) {
998+
prepare_repo_settings(the_repository);
999+
the_repository->settings.command_requires_full_index = 0;
1000+
}
9991001

10001002
argc = parse_options(argc, argv, prefix, pull_options, pull_usage, 0);
10011003

t/t0012-help.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,18 @@ test_expect_success 'git help --config-sections-for-completion' '
139139
'
140140

141141
test_expect_success 'generate builtin list' '
142+
mkdir -p sub &&
142143
git --list-cmds=builtins >builtins
143144
'
144145

145146
while read builtin
146147
do
147148
test_expect_success "$builtin can handle -h" '
148-
test_expect_code 129 git $builtin -h >output 2>&1 &&
149+
(
150+
GIT_CEILING_DIRECTORIES=$(pwd) &&
151+
export GIT_CEILING_DIRECTORIES &&
152+
test_expect_code 129 git -C sub $builtin -h >output 2>&1
153+
) &&
149154
test_i18ngrep usage output
150155
'
151156
done <builtins

0 commit comments

Comments
 (0)