Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

problems with --ignore #385

Closed
cvlmtg opened this Issue · 28 comments
@cvlmtg

what's the format of the --ignore pattern? If I do

ag --ignore '*.min.js' time website/public/vendor/ | less

ag still looks into website/public/vendor/jquery-ui.min.js

I've tried also '.*\.min\.js', '.min.js$' etc with no results.
I'm on OSX 10.9 with ag compiled through homebrew.

@mislav

Having the same problem… v0.21.0

@nmk

I am having the same problem. Patterns from .agignore are not taking effect either... v0.21.0

@lorin

Just hit this as well.

@jemiahlee

I hit this, and it looks like it's only when it's the filename that should match; if you can use a regex that matches part of the path to ignore (I know, not always possible) it will work ok. Just a possible work-around.

@iizukanao iizukanao referenced this issue from a commit in iizukanao/the_silver_searcher
@iizukanao iizukanao Fix behavior of glob patterns for ignores
Fixes #385
ff54b4b
@mightybyte

I'm having this problem too on version 0.22.0. It fails even when I don't use a wildcard and just have "js/foo.js" in my .gitignore.

@richmidwinter

I've hit this too. 0.21.0 is the latest homebrew offers.

@jwinter

This is still an issue in version 0.22.0.

@raine

Maybe a separate issue, but:

--ignore foo/bar does not work, --ignore foo works

--ignore is supposed to be an alias to --ignore-dir of ack, in which --ignore-dir foo/bar does work.

ag version 0.23.0
@mcphail

There have been a few patches which have addressed this but none have been commented upon by @ggreer. I think it is the most glaring flaw in ag just now and the underlying problem seems fairly simple.

Now there is a functioning test suite, I'd suggest someone makes a pull request with failing tests related to directory recursion and ignore files. Someone with a bit of time on their hands might be able to polish up my old patch dae7f6c to rebase off the current master and see whether it satisfies the tests.

@joechrysler

Found a temporary workaround. If you duplicate your ignore patterns like so:

ag --ignore *.min.js --ignore */*.min.js time

ag will correctly ignore files in subdirectories. Without the */ prefix, it only ignores files in the current working directory. Same thing works in the .agignore.

*.pyc
*.min.js
*-ck.js

*/*.pyc
*/*.min.js
*/*-ck.js

*Update: * looks like this only works for one level of subdirectories. Files 2 or three levels deep are still searched. :crying_cat_face:

@JianCheng

@joechrysler With the latest version, I have the same problem for *~.

I put *~ in ~/.agignore, but it does not work.
Thus I am now using

*~
*/*~
*/*/*~
*/*/*/*~
*/*/*/*/*~
*/*/*/*/*/*~

It is a workaround for me.

@John-Appleseed

Dev Folder

2012
2013
WIPCode1
WIPCode2
ag --ignore 20* model ~/Development/App

is a failure.

Is there a working version of Ag where --ignore did work?

I have tried 0.22.0 and 0.23.0

@mmwtsn

I'm seeing this as well with versions 0.22.0 and 0.23.0 installed with Homebrew on OS X 10.9.3. Ag's ignore flag works for me within the current directory but does not work recursively as @joechrysler pointed out above.

To reproduce:

$ mkdir dir
$ echo "test" > file.c
$ echo "test" > dir/file.c
$ ag --ignore=*.c test
dir/file.c
1:test

Regarding @cvlmtg's original question, syntactically Ag it is fairly flexible; all of the following work in the current directory:

$ ag --ignore=*.c main
$ ag --ignore '*.c' main
$ ag --ignore "*.c" main
@jkdf2

Having the same issue, not working recursively in subdirectories.

@sprin

Ran a git bisect, and it looks like this was introduced in 2cc28cc.

My test was ag -p .agignore needle pyproj/, where .agignore contained just "*.py".

It also looks like -p .agignore is required when the search path is not the current directory? Shouldn't .agignore be read from the current directory?

@ggreer
Thanks for ag! This is hands-down the fastest, non-indexed search tool I have seen.

@kaushalmodi

@ggreer Please fix this.
Right now I have these to ignore ~, *## and *.pdf files.

*~
*/*~
*/*/*~
*/*/*/*~
*/*/*/*/*~
*/*/*/*/*/*~
*/*/*/*/*/*/*~
*/*/*/*/*/*/*/*~
*.pdf
*/*.pdf
*/*/*.pdf
*/*/*/*.pdf
*/*/*/*/*.pdf
*/*/*/*/*/*.pdf
*/*/*/*/*/*/*.pdf
*/*/*/*/*/*/*/*.pdf
*#*#
*/*#*#
*/*/*#*#
*/*/*/*#*#
*/*/*/*/*#*#
*/*/*/*/*/*#*#
*/*/*/*/*/*/*#*#
*/*/*/*/*/*/*/*#*#
@sprin

For those looking for a workaround (besides verbose ignore files!), just run tag 0.20.0... not that hard!

For those looking to give back to this awesome project, have a look at 2cc28cc and see if you can spot the problem. Seriously, someone with an hour should be able to read through ignore.c and figure this out.

@ggreer
No worries, I am sure someone will come through on this! ag works beautifully on 0.20.0. Cheers from Berkeley.

@ggreer ggreer closed this in #401
@schmonz schmonz referenced this issue from a commit in schmonz/the_silver_searcher
@iizukanao iizukanao Fix behavior of glob patterns for ignores
Fixes #385
c9fa58c
@lucascaton

I'm having the same problem (ag version 0.25.0 here).

@sheki

still busted with ag 0.2.7 IMHO.

@eksperimental

As of version 0.28.0

$ ag -l -U --ignore '/doc/' '~r/./' elixir/*
elixir/doc/elixir/Kernel.html
elixir/lib/elixir/lib/kernel.ex
elixir/lib/elixir/test/elixir/kernel_test.exs

$ ag -l -U --ignore '/doc/' '~r/./' elixir/
elixir/lib/elixir/lib/kernel.ex
elixir/lib/elixir/test/elixir/kernel_test.exs

the * at the end of the PATH breaks the --ignore argument.

@ggreer
Owner

@eksperimental Two things:

  1. You put a forward slash at the start of your ignore pattern, which means, "Only ignore at the root level." This isn't causing a problem in your example, but it's worth noting.

  2. Ag doesn't see the star in the first example. Bash or zsh expansion is passing elixer/doc (among other paths) to ag. Ag doesn't ignore paths that are explicitly passed to it on the command line.

@eksperimental

sorry @ggreer , i didn't understand No. 2
thanks for answering,
but it is still no clear what should be the pattern to ignore any result that contains a folder named doc ?
--ignore '.*/doc/.*'

if so, it is not working:

$ ag -U -l --ignore '.*/doc/.*' '~r/./' elixir
elixir/lib/elixir/lib/kernel.ex
elixir/lib/elixir/lib/regex.ex
elixir/lib/elixir/test/elixir/kernel_test.exs
elixir/doc/elixir/+Kernel.html
elixir/doc/elixir/Regex.html
elixir/doc/elixir/Kernel.html

the only one that seems to work is:

$ ag -U -l --ignore 'doc/' '~r/./' elixir
elixir/lib/elixir/lib/kernel.ex
elixir/lib/elixir/lib/regex.ex
elixir/lib/elixir/test/elixir/kernel_test.exs

which is wrong according to your definition above, because the path of the ignored files does not start with "doc/"

thank!

@ggreer
Owner

In the first example of your previous comment, you put a forward slash at the start of your ignore pattern. That is, the pattern started with /. If it starts with /, that means "ignore only in the current directory. If it ends in a /, that means "only match if it's a directory."

Examples:

  • doc ignores any file or directory anywhere that is called "doc".

  • /doc ignores any file or directory in the root dir called "doc".

  • doc/ ignores any directory anywhere that's called "doc".

  • /doc/ ignores any directory in the root called "doc".

These examples are typical behavior for .gitignore and .hgignore. Ag isn't doing anything strange here.

Second point: If you run ag blah elxir, that's the same as cd elixer && ag blah. That means "doc" is in the root. An ignore pattern like .*/doc/.* will only match doc directories in a sub-directory. Actually, I'm not even sure that will match anything sane. Ignore patterns are fnmatch() patterns, not PCREs.

@eksperimental

thanks @ggreer it is a bit more clear now.
I think you should put in the documentation what kind of pattern it expects,
seems you use the same word (PATTERN) do describe the search PATTERN (regex).
I searched the respository and there's not reference to fnmatch().

so answering myself.
$ag -U -l --ignore 'doc/' '~r/./' elixir/
is the right command.

thanks for creating ag, I use it every day I'm with the computer pretty much

@blackb1rd blackb1rd referenced this issue from a commit in blackb1rd/the_silver_searcher
@iizukanao iizukanao Fix behavior of glob patterns for ignores
Fixes #385

Conflicts:
	src/ignore.c
430af4c
@shreevatsar

This still doesn't seem to be working, with ag version 0.30.0 (the latest available on Homebrew).

This is my .agignore file:

min.js
*.min.js
*/*.min.js
*/*/*.min.js
*/*/*/*.min.js
*/*/*/*.min.js

and yet ag -l includes files like client-app/bower_components/ember/ember.min.js. What's going on?

I notice that putting *.js in my .agignore (even with nothing else) prevents ag from examining such a file.

@decaff

FYI. If an ignore pattern is set as '*.min.js' and the patch from #680 (by @epmatsw) is applied, the complaints about ag not ignoring .min.js files should be fixed. Example:

$ ls
jj.js  jj.min.js
$ ../ag  --ignore '*.min.js' -g 'js' -l
jj.js
$
@shreevatsar

@decaff What is preventing #680 from being merged and released as part of ag?

I see lots of bugs (#413, #678 and this one #385) referencing this issue.

@decaff

@shreevatsar I think the author is very busy. Just a guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.