Skip to content

Commit 487a2b7

Browse files
pcloudsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]> Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a3bc3d0 commit 487a2b7

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)