From: Matthieu Moy <Matthieu.Moy@imag.fr>
Date: Tue, 24 Jul 2012 12:26:51 +0000 (+0200)
Subject: ignore: make sure we have an xdg path before using it
X-Git-Tag: v1.7.12-rc1~16^2~1
X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6283a376c47e7ca3327e563143c1ceda39ae25ac;p=git.git

ignore: make sure we have an xdg path before using it

Commit e3ebc35 (config: fix several access(NULL) calls, 2012-07-12) was
fixing access(NULL) calls when trying to access $HOME/.config/git/config,
but missed the ones when trying to access $HOME/.config/git/ignore. Fix
and test this.

Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

diff --git a/dir.c b/dir.c
index 390367fa6..059ec28db 100644
--- a/dir.c
+++ b/dir.c
@@ -1302,7 +1302,7 @@ void setup_standard_excludes(struct dir_struct *dir)
 	}
 	if (!access(path, R_OK))
 		add_excludes_from_file(dir, path);
-	if (!access(excludes_file, R_OK))
+	if (excludes_file && !access(excludes_file, R_OK))
 		add_excludes_from_file(dir, excludes_file);
 }
 
diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
index 1569596ab..94bb696ff 100755
--- a/t/t1306-xdg-files.sh
+++ b/t/t1306-xdg-files.sh
@@ -95,6 +95,13 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' '
 	test_must_fail git add to_be_excluded
 '
 
+test_expect_success 'Checking XDG ignore file when HOME is unset' '
+	>expected &&
+	(sane_unset HOME &&
+	 git config --unset core.excludesfile &&
+	 git ls-files --exclude-standard --ignored >actual) &&
+	test_cmp expected actual
+'
 
 test_expect_success 'Checking attributes in the XDG attributes file' '
 	echo foo >f &&