Merge branch 'jk/no-looking-at-dotgit-outside-repo-final'
authorJunio C Hamano <gitster@pobox.com>
Thu, 30 Mar 2017 21:07:13 +0000 (14:07 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 30 Mar 2017 21:07:13 +0000 (14:07 -0700)
This is the endgame of the topic to avoid blindly falling back to
".git" when the setup sequence said we are _not_ in Git repository.
A corner case that happens to work right now may be broken by a
call to die("BUG").

* jk/no-looking-at-dotgit-outside-repo-final:
setup_git_env: avoid blind fall-back to ".git"

environment.c
index 2fdba76222b8f5744f1ae84fd11e72a7a3c115cf..a17d96aa85bd9196da9090c768090aeec8b6b8be 100644 (file)
@@ -167,8 +167,11 @@ static void setup_git_env(void)
        const char *replace_ref_base;
 
        git_dir = getenv(GIT_DIR_ENVIRONMENT);
-       if (!git_dir)
+       if (!git_dir) {
+               if (!startup_info->have_repository)
+                       die("BUG: setup_git_env called without repository");
                git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+       }
        gitfile = read_gitfile(git_dir);
        git_dir = xstrdup(gitfile ? gitfile : git_dir);
        if (get_common_dir(&sb, git_dir))