path: root/attr.c
diff options
authorJeff King <>2016-10-20 06:16:41 (GMT)
committerJunio C Hamano <>2016-10-26 20:30:51 (GMT)
commitf0056f6419deb6b4e226976c571f6429875519f1 (patch)
treea24ea4c1759b100554fa832b1f6739dcc18405ae /attr.c
parent2cc2e70264e0fcba04f9ef791d144bbc8b501206 (diff)
read info/{attributes,exclude} only when in repository
The low-level attribute and gitignore code will try to look in $GIT_DIR/info for any repo-level configuration files, even if we have not actually determined that we are in a repository (e.g., running "git grep --no-index"). In such a case they end up looking for ".git/info/attributes", etc. This is generally harmless, as such a file is unlikely to exist outside of a repository, but it's still conceptually the wrong thing to do. Let's detect this situation explicitly and skip reading the file (i.e., the same behavior we'd get if we were in a repository and the file did not exist). Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'attr.c')
1 files changed, 5 insertions, 1 deletions
diff --git a/attr.c b/attr.c
index eec5d7d..1fcf042 100644
--- a/attr.c
+++ b/attr.c
@@ -531,7 +531,11 @@ static void bootstrap_attr_stack(void)
- elem = read_attr_from_file(git_path_info_attributes(), 1);
+ if (startup_info->have_repository)
+ elem = read_attr_from_file(git_path_info_attributes(), 1);
+ else
+ elem = NULL;
if (!elem)
elem = xcalloc(1, sizeof(*elem));
elem->origin = NULL;