git: ensure correct git directory setup with -h
Ensure correct git directory setup when -h is passed with commands. This specifically applies to repos with special help text configuration variables and to commands run with -h outside a repository. This will also protect against test failures in the upcoming change to BUG in prepare_repo_settings if no git directory exists. Note: this diff is better seen when ignoring whitespace changes. Co-authored-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Lessley Dennington <lessleydennington@gmail.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ea6ae410be
commit
e5b17bda8b
37
git.c
37
git.c
@ -421,27 +421,30 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
|
|||||||
int status, help;
|
int status, help;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
|
int run_setup = (p->option & (RUN_SETUP | RUN_SETUP_GENTLY));
|
||||||
|
|
||||||
prefix = NULL;
|
|
||||||
help = argc == 2 && !strcmp(argv[1], "-h");
|
help = argc == 2 && !strcmp(argv[1], "-h");
|
||||||
if (!help) {
|
if (help && (run_setup & RUN_SETUP))
|
||||||
if (p->option & RUN_SETUP)
|
/* demote to GENTLY to allow 'git cmd -h' outside repo */
|
||||||
prefix = setup_git_directory();
|
run_setup = RUN_SETUP_GENTLY;
|
||||||
else if (p->option & RUN_SETUP_GENTLY) {
|
|
||||||
int nongit_ok;
|
|
||||||
prefix = setup_git_directory_gently(&nongit_ok);
|
|
||||||
}
|
|
||||||
precompose_argv_prefix(argc, argv, NULL);
|
|
||||||
if (use_pager == -1 && p->option & (RUN_SETUP | RUN_SETUP_GENTLY) &&
|
|
||||||
!(p->option & DELAY_PAGER_CONFIG))
|
|
||||||
use_pager = check_pager_config(p->cmd);
|
|
||||||
if (use_pager == -1 && p->option & USE_PAGER)
|
|
||||||
use_pager = 1;
|
|
||||||
|
|
||||||
if ((p->option & (RUN_SETUP | RUN_SETUP_GENTLY)) &&
|
if (run_setup & RUN_SETUP) {
|
||||||
startup_info->have_repository) /* get_git_dir() may set up repo, avoid that */
|
prefix = setup_git_directory();
|
||||||
trace_repo_setup(prefix);
|
} else if (run_setup & RUN_SETUP_GENTLY) {
|
||||||
|
int nongit_ok;
|
||||||
|
prefix = setup_git_directory_gently(&nongit_ok);
|
||||||
|
} else {
|
||||||
|
prefix = NULL;
|
||||||
}
|
}
|
||||||
|
precompose_argv_prefix(argc, argv, NULL);
|
||||||
|
if (use_pager == -1 && run_setup &&
|
||||||
|
!(p->option & DELAY_PAGER_CONFIG))
|
||||||
|
use_pager = check_pager_config(p->cmd);
|
||||||
|
if (use_pager == -1 && p->option & USE_PAGER)
|
||||||
|
use_pager = 1;
|
||||||
|
if (run_setup && startup_info->have_repository)
|
||||||
|
/* get_git_dir() may set up repo, avoid that */
|
||||||
|
trace_repo_setup(prefix);
|
||||||
commit_pager_choice();
|
commit_pager_choice();
|
||||||
|
|
||||||
if (!help && get_super_prefix()) {
|
if (!help && get_super_prefix()) {
|
||||||
|
Reference in New Issue
Block a user