the_silver_searcher icon indicating copy to clipboard operation
the_silver_searcher copied to clipboard

.gitignore in sub directories is ignored

Open netjune opened this issue 6 years ago • 6 comments

It only cares about the .gitignore file in the root diretory. The .gitignore file in sub directories should not be ignored.

netjune avatar May 08 '18 11:05 netjune

Yes!!!! This problem has been bugging me for a long time! I have been wondering why ignored files in subdirectories still get found by ag!

dylan-chong avatar Jun 17 '18 03:06 dylan-chong

I don't think this issue is valid. I have found a problem with .gitignore files, but careful testing shows that ag does indeed load .gitignore files in subdirectories.

rrthomas avatar Jul 14 '18 12:07 rrthomas

Maybe it is related to content of .gitignore in subdirectory? I have a .gitignore file in a subdirectory with content as following:

/web_files
/web_files-*

Ag doesn't ignore files as expected (like test/web_files/test.html). And if I cd into the subdirectory, it ignores them as expected. Ag version: 2.1.0. I'm using rg (ripgrep) now. rg works well with this.

netjune avatar Jul 14 '18 13:07 netjune

ag is not ignoring subfolders' .gitignore, however it does not apply absolute paths correctly.

I believe that /webfiles in your subdirectory will be applied to root directory, so it will ignore root/webfiles but not root/subdirectory/webfiles which is incorrect.

bagage avatar Aug 07 '18 08:08 bagage

@bagage I believe that is the case. Example:

~/proj/foo$ git status --ignored -s
!! subdir/file.txt  <=== ignored by git

~/proj/foo$ ag -l yes
subdir/file.txt    <=== Not ignored by ag
file.txt

~/proj/foo$ cat .gitignore
cat: .gitignore: No such file or directory  <=== no top-level gitignore

~/proj/foo$ cat subdir/.gitignore
/file.txt    <=== with a leading slash

If I change subdir/.gitignore:

~/proj/foo$ cat subdir/.gitignore
file.txt    <=== No leading slash

~/proj/foo$ ag -l yes
file.txt
    (no subdir/file.txt!)

(ag 2.2.0, Ubuntu 20.04 x64).

cxw42 avatar Jun 01 '21 00:06 cxw42

... and, it turns out, this was fixed in early 2020 by commit 755c6e5c06fc38903fa0d66be68a9c8ffa525c1b! So, for the fix, compile from source.

This issue is a duplicate of #1318, and is fixed by #1354.

cxw42 avatar Jun 01 '21 00:06 cxw42