Let core.attributesfile default to $XDG_CONFIG_HOME/git/attributes
This gives the default value for the core.attributesfile variable following the exact same logic of the previous change for the core.excludesfile setting. Signed-off-by: Huynh Khoi Nguyen Nguyen <Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr> Signed-off-by: Valentin Duperray <Valentin.Duperray@ensimag.imag.fr> Signed-off-by: Franck Jonas <Franck.Jonas@ensimag.imag.fr> Signed-off-by: Lucien Kong <Lucien.Kong@ensimag.imag.fr> Signed-off-by: Thomas Nguy <Thomas.Nguy@ensimag.imag.fr> Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Huynh Khoi Nguyen Nguyen committed
Jun 22, 2012 at 11:03 UTC
684e40f657ae004d60dfa833567bec4a409d78f9
4 files changed
+44
-8
Documentation/config.txt
+3
-1
@@ -500,7 +500,9 @@ core.attributesfile::
500
In addition to '.gitattributes' (per-directory) and
501
'.git/info/attributes', git looks into this file for attributes
502
(see linkgit:gitattributes[5]). Path expansions are made the same
503
- way as for `core.excludesfile`.
503
+ way as for `core.excludesfile`. Its default value is
504
+ $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME is either not
505
+ set or empty, $HOME/.config/git/attributes is used instead.
506
507
core.editor::
508
Commands such as `commit` and `tag` that lets you edit
Documentation/gitattributes.txt
+2
@@ -75,6 +75,8 @@ repositories (i.e., attributes of interest to all users) should go into
75
`.gitattributes` files. Attributes that should affect all repositories
76
for a single user should be placed in a file specified by the
77
`core.attributesfile` configuration option (see linkgit:git-config[1]).
78
+Its default value is $XDG_CONFIG_HOME/git/attributes. If $XDG_CONFIG_HOME
79
+is either not set or empty, $HOME/.config/git/attributes is used instead.
80
Attributes for all users on a system should be placed in the
81
`$(prefix)/etc/gitattributes` file.
82
attr.c
+10
-7
@@ -497,6 +497,7 @@ static int git_attr_system(void)
497
static void bootstrap_attr_stack(void)
498
{
499
struct attr_stack *elem;
500
+ char *xdg_attributes_file;
501
502
if (attr_stack)
503
return;
@@ -515,13 +516,15 @@ static void bootstrap_attr_stack(void)
516
}
517
}
518
518
- if (git_attributes_file) {
519
- elem = read_attr_from_file(git_attributes_file, 1);
520
- if (elem) {
521
- elem->origin = NULL;
522
- elem->prev = attr_stack;
523
- attr_stack = elem;
524
- }
519
+ if (!git_attributes_file) {
520
+ home_config_paths(NULL, &xdg_attributes_file, "attributes");
521
+ git_attributes_file = xdg_attributes_file;
522
+ }
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;
528
}
529
530
if (!is_bare_repository() || direction == GIT_ATTR_INDEX) {
t/t1306-xdg-files.sh
+29
@@ -96,4 +96,33 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' '
96
'
97
98
99
+test_expect_success 'Checking attributes in the XDG attributes file' '
100
+ echo foo >f &&
101
+ git check-attr -a f >actual &&
102
+ test_line_count -eq 0 actual &&
103
+ echo "f attr_f" >"$HOME"/.config/git/attributes &&
104
+ echo "f: attr_f: set" >expected &&
105
+ git check-attr -a f >actual &&
106
+ test_cmp expected actual
107
+'
108
+
109
+
110
+test_expect_success 'Checking attributes in both XDG and local attributes files' '
111
+ echo "f -attr_f" >.gitattributes &&
112
+ echo "f: attr_f: unset" >expected &&
113
+ git check-attr -a f >actual &&
114
+ test_cmp expected actual
115
+'
116
+
117
+
118
+test_expect_success 'Checking attributes in a non-XDG global attributes file' '
119
+ test_might_fail rm .gitattributes &&
120
+ echo "f attr_f=test" >"$HOME"/my_gitattributes &&
121
+ git config core.attributesfile "$HOME"/my_gitattributes &&
122
+ echo "f: attr_f: test" >expected &&
123
+ git check-attr -a f >actual &&
124
+ test_cmp expected actual
125
+'
126
+
127
+
128
test_done