Skip to content

Commit f0056f6

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2cc2e70 commit f0056f6

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

attr.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,11 @@ static void bootstrap_attr_stack(void)
531531
debug_push(elem);
532532
}
533533

534-
elem = read_attr_from_file(git_path_info_attributes(), 1);
534+
if (startup_info->have_repository)
535+
elem = read_attr_from_file(git_path_info_attributes(), 1);
536+
else
537+
elem = NULL;
538+
535539
if (!elem)
536540
elem = xcalloc(1, sizeof(*elem));
537541
elem->origin = NULL;

dir.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2237,8 +2237,6 @@ static GIT_PATH_FUNC(git_path_info_exclude, "info/exclude")
22372237

22382238
void setup_standard_excludes(struct dir_struct *dir)
22392239
{
2240-
const char *path;
2241-
22422240
dir->exclude_per_dir = ".gitignore";
22432241

22442242
/* core.excludefile defaulting to $XDG_HOME/git/ignore */
@@ -2249,10 +2247,12 @@ void setup_standard_excludes(struct dir_struct *dir)
22492247
dir->untracked ? &dir->ss_excludes_file : NULL);
22502248

22512249
/* per repository user preference */
2252-
path = git_path_info_exclude();
2253-
if (!access_or_warn(path, R_OK, 0))
2254-
add_excludes_from_file_1(dir, path,
2255-
dir->untracked ? &dir->ss_info_exclude : NULL);
2250+
if (startup_info->have_repository) {
2251+
const char *path = git_path_info_exclude();
2252+
if (!access_or_warn(path, R_OK, 0))
2253+
add_excludes_from_file_1(dir, path,
2254+
dir->untracked ? &dir->ss_info_exclude : NULL);
2255+
}
22562256
}
22572257

22582258
int remove_path(const char *name)

0 commit comments

Comments
 (0)