Skip to content

Commit f1c126b

Browse files
peffgitster
authored andcommitted
setup: set startup_info->have_repository more reliably
When setup_git_directory() is called, we set a flag in startup_info to indicate we have a repository. But there are a few other mechanisms by which we might set up a repo: 1. When creating a new repository via init_db(), we transition from no-repo to being in a repo. We should tweak this flag at that moment. 2. In enter_repo(), a stricter form of setup_git_directory() used by server-side programs, we check the repository format config. After doing so, we know we're in a repository, and can set the flag. With these changes, library code can now reliably tell whether we are in a repository and act accordingly. We'll leave the "prefix" field as NULL, which is what happens when setup_git_directory() finds there is no prefix. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 46c3cd4 commit f1c126b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

builtin/init-db.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir,
322322
set_git_dir(real_path(git_dir));
323323
git_link = NULL;
324324
}
325+
startup_info->have_repository = 1;
325326
return 0;
326327
}
327328

setup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,9 @@ int check_repository_format_version(const char *var, const char *value, void *cb
986986

987987
int check_repository_format(void)
988988
{
989-
return check_repository_format_gently(get_git_dir(), NULL);
989+
check_repository_format_gently(get_git_dir(), NULL);
990+
startup_info->have_repository = 1;
991+
return 0;
990992
}
991993

992994
/*

0 commit comments

Comments
 (0)