From 5adf84ebb375eeee998edef9a2b5aaa05df677d0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 24 Jul 2012 07:53:05 -0400 Subject: test-lib.sh: unset XDG_CONFIG_HOME Now that git respects XDG_CONFIG_HOME for some lookups, we must be sure to cleanse the test environment. Otherwise, the user's XDG_CONFIG_HOME could influence the test results. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/test-lib.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/test-lib.sh b/t/test-lib.sh index 9e2b71132a..2ac9536185 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -61,6 +61,7 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $(perl -e ' my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); print join("\n", @vars); ') +unset XDG_CONFIG_HOME GIT_AUTHOR_EMAIL=author@example.com GIT_AUTHOR_NAME='A U Thor' GIT_COMMITTER_EMAIL=committer@example.com -- cgit v1.2.3 From f0c1c15c41bdcdaf71c69355ac83789466820879 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 24 Jul 2012 07:53:57 -0400 Subject: attr: make sure we have an xdg path before using it If we don't have a core.attributesfile configured, we fall back to checking XDG config, which is usually $HOME/.config/git/attributes. However, if $HOME is unset, then home_config_paths will return NULL, and we end up calling fopen(NULL). Depending on your system, this may or may not cause the accompanying test to fail (e.g., on Linux and glibc, the address will go straight to open, which will return EFAULT). However, valgrind will reliably notice the error. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- attr.c | 12 +++++++----- t/t1306-xdg-files.sh | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/attr.c b/attr.c index aef93d896f..b52efb55a0 100644 --- a/attr.c +++ b/attr.c @@ -520,11 +520,13 @@ static void bootstrap_attr_stack(void) home_config_paths(NULL, &xdg_attributes_file, "attributes"); git_attributes_file = xdg_attributes_file; } - elem = read_attr_from_file(git_attributes_file, 1); - if (elem) { - elem->origin = NULL; - elem->prev = attr_stack; - attr_stack = elem; + if (git_attributes_file) { + elem = read_attr_from_file(git_attributes_file, 1); + if (elem) { + elem->origin = NULL; + elem->prev = attr_stack; + attr_stack = elem; + } } if (!is_bare_repository() || direction == GIT_ATTR_INDEX) { diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh index 3c75c3f2e7..1569596ab3 100755 --- a/t/t1306-xdg-files.sh +++ b/t/t1306-xdg-files.sh @@ -106,6 +106,12 @@ test_expect_success 'Checking attributes in the XDG attributes file' ' test_cmp expected actual ' +test_expect_success 'Checking XDG attributes when HOME is unset' ' + >expected && + (sane_unset HOME && + git check-attr -a f >actual) && + test_cmp expected actual +' test_expect_success 'Checking attributes in both XDG and local attributes files' ' echo "f -attr_f" >.gitattributes && -- cgit v1.2.3 From 6283a376c47e7ca3327e563143c1ceda39ae25ac Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Tue, 24 Jul 2012 14:26:51 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- dir.c | 2 +- t/t1306-xdg-files.sh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dir.c b/dir.c index 390367fa67..059ec28dbb 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 1569596ab3..94bb696ff4 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 && -- cgit v1.2.3 From 22ae029a1e0631570a2db5d030e5755f9be96eee Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 24 Jul 2012 08:27:10 -0400 Subject: t1306: check that XDG_CONFIG_HOME works This should override $HOME/.config, but we never actually tested it. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1306-xdg-files.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh index 94bb696ff4..8b14ab187c 100755 --- a/t/t1306-xdg-files.sh +++ b/t/t1306-xdg-files.sh @@ -38,6 +38,13 @@ test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\'' test_cmp expected actual ' +test_expect_success '"$XDG_CONFIG_HOME overrides $HOME/.config/git' ' + mkdir -p "$HOME"/xdg/git && + echo "[user]name = in_xdg" >"$HOME"/xdg/git/config && + echo in_xdg >expected && + XDG_CONFIG_HOME="$HOME"/xdg git config --get-all user.name >actual && + test_cmp expected actual +' test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' ' >.gitconfig && @@ -80,6 +87,17 @@ test_expect_success 'Exclusion of a file in the XDG ignore file' ' test_must_fail git add to_be_excluded ' +test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/ignore' ' + mkdir -p "$HOME"/xdg/git && + echo content >excluded_by_xdg_only && + echo excluded_by_xdg_only >"$HOME"/xdg/git/ignore && + test_when_finished "git read-tree --empty" && + (XDG_CONFIG_HOME="$HOME/xdg" && + export XDG_CONFIG_HOME && + git add to_be_excluded && + test_must_fail git add excluded_by_xdg_only + ) +' test_expect_success 'Exclusion in both XDG and local ignore files' ' echo to_be_excluded >.gitignore && @@ -120,6 +138,14 @@ test_expect_success 'Checking XDG attributes when HOME is unset' ' test_cmp expected actual ' +test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' ' + mkdir -p "$HOME"/xdg/git && + echo "f attr_f=xdg" >"$HOME"/xdg/git/attributes && + echo "f: attr_f: xdg" >expected && + XDG_CONFIG_HOME="$HOME/xdg" git check-attr -a f >actual && + test_cmp expected actual +' + test_expect_success 'Checking attributes in both XDG and local attributes files' ' echo "f -attr_f" >.gitattributes && echo "f: attr_f: unset" >expected && -- cgit v1.2.3