Make setup_git_env() resolve .git file when $GIT_DIR is not specified
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 31 Aug 2013 01:04:14 +0000 (08:04 +0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 3 Sep 2013 18:14:58 +0000 (11:14 -0700)
This makes reinitializing on a .git file repository work.

This is probably the only case that setup_git_env() (via
set_git_dir()) is called on a .git file. Other cases in
setup_git_dir_gently() and enter_repo() both cover .git file case
explicitly because they need to verify the target repo is valid.

Reported-by: Ximin Luo <infinity0@gmx.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
t/t0001-init.sh
index e2e75c16602d8e5841c2461defaba7b9866115d8..03c9eb7a2ea8ca7e58416a3b0d17e7e0bdc038e5 100644 (file)
@@ -123,14 +123,13 @@ static char *expand_namespace(const char *raw_namespace)
 
 static void setup_git_env(void)
 {
+       const char *gitfile;
+
        git_dir = getenv(GIT_DIR_ENVIRONMENT);
-       git_dir = git_dir ? xstrdup(git_dir) : NULL;
-       if (!git_dir) {
-               git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
-               git_dir = git_dir ? xstrdup(git_dir) : NULL;
-       }
        if (!git_dir)
                git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
+       gitfile = read_gitfile(git_dir);
+       git_dir = xstrdup(gitfile ? gitfile : git_dir);
        git_object_dir = getenv(DB_ENVIRONMENT);
        if (!git_object_dir) {
                git_object_dir = xmalloc(strlen(git_dir) + 9);
index ad664105646d4579a4e31ea5d230268acc33c0f5..9fb582b192e7d44856d3687234de922217e511f4 100755 (executable)
@@ -379,6 +379,10 @@ test_expect_success 'init with separate gitdir' '
        test -d realgitdir/refs
 '
 
+test_expect_success 're-init on .git file' '
+       ( cd newdir && git init )
+'
+
 test_expect_success 're-init to update git link' '
        (
        cd newdir &&