1

Java files are listed in the known file types (using ag --list-file-types) but aren't aren't returned in the ag search results below unless I use the -t flag (-a and -U also return Java files in the results). Is this expected behavior? I have .gitignore files strewn about but this Java file is not being ignored in any of those files.

~/src $ ag "ACADEMIC"|grep java
~/src $ ag "ACADEMIC" -t|grep java
{path}/StudentRowMapper.java:23:        Student.setAcademicLevel(rs.getString("ACADEMIC_LEVEL"));
Andrew Goodnough
  • 1,068
  • 7
  • 8

1 Answers1

1

No that is not expected behavior. And, in my quick test, not reproducing. Ag will search through .java files.

You don't need to specify searching java files. The "--java" file-type flag is for restricting a search to only .java and .properties files. For example:

~/src $ ag --java "ACADEMIC"

Since you're getting a result using -a or -U, but not without them, it appears as though you've got an .ignore file effecting ag. Ag ignores files include the following patterns: .gitignore, .hgignore, or .ignore. These files can be located anywhere in the directories searched. Also, keep in mind, binary files are ignored by default. In addition, ag looks in the file $HOME/.agignore for ignore patterns.

(From the man page:) If you want to ignore .gitignore and .hgignore, but still take .ignore into account, use -U flag. The -t option will search all text files; -a to search all files; and -u to search all, including hidden files.

gregory
  • 10,969
  • 2
  • 30
  • 42
  • Thanks for you response but I don't have any .ignore or .hgignore files and none of my .gitignore files have entries referencing/excluding java files. – Andrew Goodnough Apr 12 '18 at 17:51
  • +2 if I could. I had a .gitignore in my home directory and now it's working exactly as I'd expect. – wattry Jan 04 '21 at 02:45