Skip to content

Commit f8aeacf

Browse files
committed
Merge branch 'nd/git-dir-pointing-at-gitfile' into maint
* nd/git-dir-pointing-at-gitfile: Make setup_git_env() resolve .git file when $GIT_DIR is not specified
2 parents 7d9dd6d + 487a2b7 commit f8aeacf

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

environment.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,13 @@ static char *expand_namespace(const char *raw_namespace)
123123

124124
static void setup_git_env(void)
125125
{
126+
const char *gitfile;
127+
126128
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-
}
132129
if (!git_dir)
133130
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
131+
gitfile = read_gitfile(git_dir);
132+
git_dir = xstrdup(gitfile ? gitfile : git_dir);
134133
git_object_dir = getenv(DB_ENVIRONMENT);
135134
if (!git_object_dir) {
136135
git_object_dir = xmalloc(strlen(git_dir) + 9);

t/t0001-init.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ test_expect_success 'init with separate gitdir' '
379379
test -d realgitdir/refs
380380
'
381381

382+
test_expect_success 're-init on .git file' '
383+
( cd newdir && git init )
384+
'
385+
382386
test_expect_success 're-init to update git link' '
383387
(
384388
cd newdir &&

0 commit comments

Comments
 (0)