Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.gitignore not taken into account when the current working directory is a subdirectory #144

Open
Flimm opened this issue Feb 1, 2013 · 14 comments
Labels

Comments

@Flimm
Copy link

Flimm commented Feb 1, 2013

If I run ag in the directory that contains .gitignore, it reads it and takes it into account. However, if I run ag in a subdirectory of the git working directory, it doesn't take it into account any more.

@emberian
Copy link
Contributor

emberian commented Mar 2, 2013

I'm working on a patch for this

@dahjelle
Copy link

dahjelle commented Mar 8, 2013

Just ran into this…be great to see it included!

@emberian
Copy link
Contributor

emberian commented Mar 8, 2013

One potential problem is that it doesn't stop when it hits a .gitignore, and it will catch every parent .gitignore, which isn't how git behaves.

@Flimm
Copy link
Author

Flimm commented Mar 11, 2013

Git does read every parent .gitignore until it reaches the directory with .git.

@emberian
Copy link
Contributor

It doesn't read beyond that, though, which is what I was trying to get
across. Current code reads everything up to the root directory.

On Mon, Mar 11, 2013 at 7:57 AM, David D Lowe notifications@github.comwrote:

Git does read every parent .gitignore until it reaches the directory with
.git.


Reply to this email directly or view it on GitHubhttps://github.com//issues/144#issuecomment-14709325
.

@jucor
Copy link

jucor commented Jul 22, 2013

Any news on this patch? I just realized that Ag ignore list is not the same as git. It is probably linked to this issue. Does Ag also read the global ignore file from config.excludesfile?

mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Oct 30, 2013
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Nov 4, 2013
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Nov 6, 2013
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Nov 29, 2013
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Dec 4, 2013
Attempt to fix issue 275

Only increment the scandir baton when recursing

Fix ggreer#285 but needs testing for more complex directories

Check ignore paths based on correct baton level

Fix ggreer#287 but doesn't fix ggreer#144

Stop comparing terminating NULL in path string

Might save a few cycles...

Handle absolute .gitignore patterns properly

Pattern /b/c/d should ignore /b/c/d but not a/b/c/d
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Dec 4, 2013
Attempt to fix issue 275

Only increment the scandir baton when recursing

Fix ggreer#285 but needs testing for more complex directories

Check ignore paths based on correct baton level

Fix ggreer#287 but doesn't fix ggreer#144

Stop comparing terminating NULL in path string

Might save a few cycles...

Handle absolute .gitignore patterns properly

Pattern /b/c/d should ignore /b/c/d but not a/b/c/d
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Dec 8, 2013
Attempt to fix issue 275

Only increment the scandir baton when recursing

Fix ggreer#285 but needs testing for more complex directories

Check ignore paths based on correct baton level

Fix ggreer#287 but doesn't fix ggreer#144

Stop comparing terminating NULL in path string

Might save a few cycles...

Handle absolute .gitignore patterns properly

Pattern /b/c/d should ignore /b/c/d but not a/b/c/d
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Jan 22, 2014
Attempt to fix issue 275

Only increment the scandir baton when recursing

Fix ggreer#285 but needs testing for more complex directories

Check ignore paths based on correct baton level

Fix ggreer#287 but doesn't fix ggreer#144

Stop comparing terminating NULL in path string

Might save a few cycles...

Handle absolute .gitignore patterns properly

Pattern /b/c/d should ignore /b/c/d but not a/b/c/d
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Jan 24, 2014
Attempt to fix issue 275

Only increment the scandir baton when recursing

Fix ggreer#285 but needs testing for more complex directories

Check ignore paths based on correct baton level

Fix ggreer#287 but doesn't fix ggreer#144

Stop comparing terminating NULL in path string

Might save a few cycles...

Handle absolute .gitignore patterns properly

Pattern /b/c/d should ignore /b/c/d but not a/b/c/d
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Jan 31, 2014
Attempt to fix issue 275

Only increment the scandir baton when recursing

Fix ggreer#285 but needs testing for more complex directories

Check ignore paths based on correct baton level

Fix ggreer#287 but doesn't fix ggreer#144

Stop comparing terminating NULL in path string

Might save a few cycles...

Handle absolute .gitignore patterns properly

Pattern /b/c/d should ignore /b/c/d but not a/b/c/d
mcphail pushed a commit to mcphail/the_silver_searcher that referenced this issue Feb 19, 2014
Attempt to fix issue 275

Only increment the scandir baton when recursing

Fix ggreer#285 but needs testing for more complex directories

Check ignore paths based on correct baton level

Fix ggreer#287 but doesn't fix ggreer#144

Stop comparing terminating NULL in path string

Might save a few cycles...

Handle absolute .gitignore patterns properly

Pattern /b/c/d should ignore /b/c/d but not a/b/c/d
@ggreer ggreer added the ignore label Sep 26, 2014
@sandermarechal
Copy link

Any news on this issue? I'd love to see it resolved. This issue makes ag hard to work with in large repositories.

@tremby
Copy link

tremby commented Jun 4, 2015

I'd recommend just using git grep. You know it'll always respect the .gitignore file properly.

@dbedrenko
Copy link

@sandermarechal @tremby Or ack for that matter.

A crappy workaround with ag is to make .agignore a symbolic link to whatever repo you are currently working on (in my case it would be my current project at work).

Can't we just re-use the .gitignore-finding and parsing code from the git source itself? I see so many issues related to .gitignore.

@Flimm
Copy link
Author

Flimm commented Aug 12, 2015

The thing is, .agignore isn't intrepreted exactly like .gitignore. For example, in .gitignore, if a line starts with a forward slash, it matches patterns directly in the parent directory. .agignore doesn't seem to accept lines that begin with a forward slash.

@tremby
Copy link

tremby commented Aug 12, 2015

At the risk of being a broken record, give git grep a go. It's as fast as ag, or seems to be, and will always get your .gitignore right. My only annoyance with it is that in its machine readable output it doesn't give the column number, so it's not quite as useful as ag etc for quickfix lists in vim.

@velrest
Copy link

velrest commented Jun 14, 2018

Whats the status of this issue? Is this fixed already or still WIP? This would really help since i end up always searching thru all my build files etc.

@ryanblakeley
Copy link

ryanblakeley commented Jan 8, 2019

If you're in a pinch, you can use .ignore, from https://github.com/ggreer/the_silver_searcher/wiki/Advanced-Usage#ignore . IMO not the most elegant solution. I'd prefer to just rely on .gitignore, even if it's in a parent. Is there something that makes it super hard to patch support for .gitignore in parent dirs? If I do ag -Q 'my search' mysubdir to confine my search to a sub-dir I immediately lose the benefit of .gitignore. that's kind of a bummer. edit: I ended up replacing ag with rg. kind of nice bonus not having to add the -Q option for string-literals.

@dosentmatter
Copy link

Here's a workaround using a shell bash function. It checks if you are currently in a git repo and if so, gets the .gitignore. If not, it passes an empty string to -p '', which seems to get ignored.

ag() {
  command ag \
    -p "$(git rev-parse --is-inside-work-tree &>/dev/null && echo "$(git rev-parse --show-toplevel)/.gitignore")" \
    "$@"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests