Make setup_git_env() resolve .git file when $GIT_DIR is not specified
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>
Nguyễn Thái Ngọc Duy committed
Aug 31, 2013 at 08:04 UTC
487a2b732230608fe7f2cdc46c9f11bd646cb1ac
2 files changed
+8
-5
environment.c
+4
-5
@@ -123,14 +123,13 @@ static char *expand_namespace(const char *raw_namespace)
123
124
static void setup_git_env(void)
125
{
126
+ const char *gitfile;
127
+
128
git_dir = getenv(GIT_DIR_ENVIRONMENT);
127
- git_dir = git_dir ? xstrdup(git_dir) : NULL;
128
- if (!git_dir) {
129
- git_dir = read_gitfile(DEFAULT_GIT_DIR_ENVIRONMENT);
130
- git_dir = git_dir ? xstrdup(git_dir) : NULL;
131
- }
129
if (!git_dir)
130
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
131
+ gitfile = read_gitfile(git_dir);
132
+ git_dir = xstrdup(gitfile ? gitfile : git_dir);
133
git_object_dir = getenv(DB_ENVIRONMENT);
134
if (!git_object_dir) {
135
git_object_dir = xmalloc(strlen(git_dir) + 9);
t/t0001-init.sh
+4
@@ -379,6 +379,10 @@ test_expect_success 'init with separate gitdir' '
379
test -d realgitdir/refs
380
'
381
382
+test_expect_success 're-init on .git file' '
383
+ ( cd newdir && git init )
384
+'
385
+
386
test_expect_success 're-init to update git link' '
387
(
388
cd newdir &&