Given that about 80% builtin commands will need to search for a repository, we should keep the repository found in alias handling code. Until we are clear there's no need for a repository, then we can undo the setup with unset_git_directory(). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx> --- git.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/git.c b/git.c index 17482dd..d6513f1 100644 --- a/git.c +++ b/git.c @@ -152,7 +152,8 @@ static int handle_alias(int *argcp, const char ***argv) char *alias_string; int unused_nongit; - setup_git_directory_gently(&unused_nongit); + if (!startup_info->have_repository) + setup_git_directory_gently(&unused_nongit); alias_command = (*argv)[0]; alias_string = alias_lookup(alias_command); @@ -209,8 +210,6 @@ static int handle_alias(int *argcp, const char ***argv) ret = 1; } - unset_git_directory(startup_info->prefix); - errno = saved_errno; return ret; @@ -240,12 +239,18 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv) startup_info->help = argc == 2 && !strcmp(argv[1], "-h"); if (!startup_info->help) { - if (p->option & RUN_SETUP) + if ((p->option & RUN_SETUP) && !startup_info->have_repository) setup_git_directory(); - if (p->option & RUN_SETUP_GENTLY) { + else if ((p->option & RUN_SETUP_GENTLY) && !startup_info->have_repository) { int nongit_ok; setup_git_directory_gently(&nongit_ok); } + else if (startup_info->have_repository) { + if (p->option & (RUN_SETUP_GENTLY | RUN_SETUP)) + ; /* done already */ + else + unset_git_directory(startup_info->prefix); + } if (use_pager == -1 && p->option & RUN_SETUP) use_pager = check_pager_config(p->cmd); -- 1.7.0.rc1.541.g2da82.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html