the_silver_searcher: Doesn't respect "match-beginning" gitignore patterns in subdirs

In .gitignore files, ignore patterns can be prefixed with a “/”. man gitignore says:

A leading slash matches the beginning of the pathname. For example, "/*.c" matches "cat-file.c"
but not "mozilla-sha1/sha1.c".

ag currently doesn’t apply such patterns when they match files in subdirectories. Steps to reproduce:

% mkdir ag-test                                                                                            % cd ag-test                                                                                               % mkdir ignored
% echo 'hello' > ignored/a
% echo 'hello' > b
% ag hello
b
1:hello

ignored/a
1:hello
% echo '/ignored/*' > .gitignore  ## should ignore "a", but doesn't
% ag hello
b
1:hello

ignored/a
1:hello
% echo 'ignored/*' > .gitignore
% ag hello
b
1:hello

However, the non-subdir case currently works correctly:

% echo '/b' > .gitignore
% ag hello
ignored/a
1:hello

Other than this minor hiccup, it’s awesomeness all the way. 😃

About this issue

  • Original URL
  • State: open
  • Created 11 years ago
  • Reactions: 2
  • Comments: 31 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Can confirm the issue. It’s a really painful having ag go through dist assets – which are commonly exempted from version control via “/dist” in the .gitignore file.

I can also confirm the issue. And another problem that I think it’s still related to the .gitignore file is a case where you ignore a entire folder but some files as exemplified by the following hypothetical .gitigore:

ignored/*
!ignored/not_ignored

If I search for some content the file ignored/not_ignored will not be included in the files for the search.