setup: set startup_info->have_repository more reliably
authorJeff King <peff@peff.net>
Sat, 5 Mar 2016 22:11:34 +0000 (17:11 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Mar 2016 01:18:16 +0000 (17:18 -0800)
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/init-db.c
setup.c
index 6223b7d46af346b0d96870ee0c647ab9a5440b33..da531f6b766fb300d8c1fff0d94a0756bbbf1f6f 100644 (file)
@@ -322,6 +322,7 @@ int set_git_dir_init(const char *git_dir, const char *real_git_dir,
                set_git_dir(real_path(git_dir));
                git_link = NULL;
        }
+       startup_info->have_repository = 1;
        return 0;
 }
 
diff --git a/setup.c b/setup.c
index fa7a306287a9daee48b6d970b4e2e7c3f96cd46e..3439ec6d815f823ed853251c9afa94d14d78556a 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -986,7 +986,9 @@ int check_repository_format_version(const char *var, const char *value, void *cb
 
 int check_repository_format(void)
 {
-       return check_repository_format_gently(get_git_dir(), NULL);
+       check_repository_format_gently(get_git_dir(), NULL);
+       startup_info->have_repository = 1;
+       return 0;
 }
 
 /*