Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
peff authored and gitster committed Oct 26, 2016
1 parent 2cc2e70 commit f0056f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 5 additions & 1 deletion attr.c
Expand Up @@ -531,7 +531,11 @@ static void bootstrap_attr_stack(void)
debug_push(elem);
}

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;
Expand Down
12 changes: 6 additions & 6 deletions dir.c
Expand Up @@ -2237,8 +2237,6 @@ static GIT_PATH_FUNC(git_path_info_exclude, "info/exclude")

void setup_standard_excludes(struct dir_struct *dir)
{
const char *path;

dir->exclude_per_dir = ".gitignore";

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

/* per repository user preference */
path = git_path_info_exclude();
if (!access_or_warn(path, R_OK, 0))
add_excludes_from_file_1(dir, path,
dir->untracked ? &dir->ss_info_exclude : NULL);
if (startup_info->have_repository) {
const char *path = git_path_info_exclude();
if (!access_or_warn(path, R_OK, 0))
add_excludes_from_file_1(dir, path,
dir->untracked ? &dir->ss_info_exclude : NULL);
}
}

int remove_path(const char *name)
Expand Down

0 comments on commit f0056f6

Please sign in to comment.