summaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2013-08-31 08:04:14 +0700
committerJunio C Hamano <gitster@pobox.com>2013-09-03 11:14:58 -0700
commit487a2b732230608fe7f2cdc46c9f11bd646cb1ac (patch)
treeed1d7d7dd69c2338d686b0c610171090c9e402bc /environment.c
parenta3bc3d070cacf07dbe11b4bfec57554c8bbf1957 (diff)
downloadgit-487a2b732230608fe7f2cdc46c9f11bd646cb1ac.tar.gz
Make setup_git_env() resolve .git file when $GIT_DIR is not specifiednd/git-dir-pointing-at-gitfile
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>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c9
1 files changed, 4 insertions, 5 deletions
diff --git a/environment.c b/environment.c
index e2e75c1660..03c9eb7a2e 100644
--- a/environment.c
+++ b/environment.c
@@ -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);