Skip to content

Commit 0d94427

Browse files
committed
Merge branch 'mm/config-xdg'
Finishing touches to the XDG support (new feature for 1.7.12) and tests. * mm/config-xdg: t1306: check that XDG_CONFIG_HOME works ignore: make sure we have an xdg path before using it attr: make sure we have an xdg path before using it test-lib.sh: unset XDG_CONFIG_HOME
2 parents 7b9f29c + 22ae029 commit 0d94427

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

attr.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,13 @@ static void bootstrap_attr_stack(void)
520520
home_config_paths(NULL, &xdg_attributes_file, "attributes");
521521
git_attributes_file = xdg_attributes_file;
522522
}
523-
elem = read_attr_from_file(git_attributes_file, 1);
524-
if (elem) {
525-
elem->origin = NULL;
526-
elem->prev = attr_stack;
527-
attr_stack = elem;
523+
if (git_attributes_file) {
524+
elem = read_attr_from_file(git_attributes_file, 1);
525+
if (elem) {
526+
elem->origin = NULL;
527+
elem->prev = attr_stack;
528+
attr_stack = elem;
529+
}
528530
}
529531

530532
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {

dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ void setup_standard_excludes(struct dir_struct *dir)
13131313
}
13141314
if (!access(path, R_OK))
13151315
add_excludes_from_file(dir, path);
1316-
if (!access(excludes_file, R_OK))
1316+
if (excludes_file && !access(excludes_file, R_OK))
13171317
add_excludes_from_file(dir, excludes_file);
13181318
}
13191319

t/t1306-xdg-files.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''
3838
test_cmp expected actual
3939
'
4040

41+
test_expect_success '"$XDG_CONFIG_HOME overrides $HOME/.config/git' '
42+
mkdir -p "$HOME"/xdg/git &&
43+
echo "[user]name = in_xdg" >"$HOME"/xdg/git/config &&
44+
echo in_xdg >expected &&
45+
XDG_CONFIG_HOME="$HOME"/xdg git config --get-all user.name >actual &&
46+
test_cmp expected actual
47+
'
4148

4249
test_expect_success 'read with --get: xdg file exists and ~/.gitconfig exists' '
4350
>.gitconfig &&
@@ -80,6 +87,17 @@ test_expect_success 'Exclusion of a file in the XDG ignore file' '
8087
test_must_fail git add to_be_excluded
8188
'
8289

90+
test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/ignore' '
91+
mkdir -p "$HOME"/xdg/git &&
92+
echo content >excluded_by_xdg_only &&
93+
echo excluded_by_xdg_only >"$HOME"/xdg/git/ignore &&
94+
test_when_finished "git read-tree --empty" &&
95+
(XDG_CONFIG_HOME="$HOME/xdg" &&
96+
export XDG_CONFIG_HOME &&
97+
git add to_be_excluded &&
98+
test_must_fail git add excluded_by_xdg_only
99+
)
100+
'
83101

84102
test_expect_success 'Exclusion in both XDG and local ignore files' '
85103
echo to_be_excluded >.gitignore &&
@@ -95,6 +113,13 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' '
95113
test_must_fail git add to_be_excluded
96114
'
97115

116+
test_expect_success 'Checking XDG ignore file when HOME is unset' '
117+
>expected &&
118+
(sane_unset HOME &&
119+
git config --unset core.excludesfile &&
120+
git ls-files --exclude-standard --ignored >actual) &&
121+
test_cmp expected actual
122+
'
98123

99124
test_expect_success 'Checking attributes in the XDG attributes file' '
100125
echo foo >f &&
@@ -106,6 +131,20 @@ test_expect_success 'Checking attributes in the XDG attributes file' '
106131
test_cmp expected actual
107132
'
108133

134+
test_expect_success 'Checking XDG attributes when HOME is unset' '
135+
>expected &&
136+
(sane_unset HOME &&
137+
git check-attr -a f >actual) &&
138+
test_cmp expected actual
139+
'
140+
141+
test_expect_success '$XDG_CONFIG_HOME overrides $HOME/.config/git/attributes' '
142+
mkdir -p "$HOME"/xdg/git &&
143+
echo "f attr_f=xdg" >"$HOME"/xdg/git/attributes &&
144+
echo "f: attr_f: xdg" >expected &&
145+
XDG_CONFIG_HOME="$HOME/xdg" git check-attr -a f >actual &&
146+
test_cmp expected actual
147+
'
109148

110149
test_expect_success 'Checking attributes in both XDG and local attributes files' '
111150
echo "f -attr_f" >.gitattributes &&

t/test-lib.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $(perl -e '
6161
my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env);
6262
print join("\n", @vars);
6363
')
64+
unset XDG_CONFIG_HOME
6465
6566
GIT_AUTHOR_NAME='A U Thor'
6667

0 commit comments

Comments
 (0)