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

Support for .gitignore in configuration #218

Closed
ianks opened this issue Jan 29, 2015 · 16 comments
Closed

Support for .gitignore in configuration #218

ianks opened this issue Jan 29, 2015 · 16 comments

Comments

@ianks
Copy link

ianks commented Jan 29, 2015

I want CTags to ignore the files listed in my gitignore. Would this be something that would be desirable for many? If so, I will dive into some code any see what I can do.

@ffes
Copy link
Member

ffes commented Jan 29, 2015

I like the idea.

But I think it should be a command line option and not the default behavior. Curious what others think about this.

And it should not be limited to only .gitignore. For instance, there are still people using CVS, so when this option is enabled it should also use .cvsignore. Other VCS's that work with ignore-files should be supported as well. I have no experience with other VCS's, but I know that Mercurial uses .hgignore.

@fishman
Copy link
Contributor

fishman commented Jan 29, 2015

i think this is one of the main reasons why people prefer ack and ag over grep. but i'm not sure if it should be gitignore but rather a more generic whitelist

@ffes
Copy link
Member

ffes commented Jan 30, 2015

The basic code to do this seems quite simple. In options.c around line 2680 I added this line to test it.

processExcludeOption (NULL, "@.gitignore");

See man ctags about the --exclude option for details.
Note that the ignore file has to exist or else ctags will abort.

./ctags --verbose -R . shows adding exclude patterns from .gitignore
But for instance ctags.exe is not ignore even though it is mentioned in .gitignore. So there seems to be a problem. I'll fire up the debugger to find out why it doesn't work as expected.

And I am not sure yet what the default behavior should be: enabled or disabled. And there must be an option (-X and/or a long option?) to enable/disable this. Know that ctags has more long options with a "=[yes|no]" extension.

I think there is not much wrong with using all the common ignore files.

@vhda
Copy link
Contributor

vhda commented Jan 30, 2015

Considering that --exclude apparently supports .gitignore-like files, I think we can consider that this feature is already implemented. I don't see any advantage in using --enable-gitignore (or similar) to ctags instead of --exclude="@.gitignore".
Maybe we could include the usage of @.gitignore as an example of this argument in the man page?

@ianks
Copy link
Author

ianks commented Jan 31, 2015

The problem is that it doesn't honor things like global .gitignore, etc.
Also, are we sure the regexes in the gitignore are honored correctly? I
will tell this lasted this weekend.
On Fri, Jan 30, 2015 at 7:55 AM Vitor notifications@github.com wrote:

Considering that --exclude apparently supports .gitignore-like files, I
think we can consider that this feature is already implemented. I don't see
any advantage in using --enable-gitignore (or similar) to ctags instead
of --exclude="@.gitignore".
Maybe we could include the usage of @.gitignore as an example of this
argument in the man page?


Reply to this email directly or view it on GitHub
#218 (comment).

@ffes
Copy link
Member

ffes commented Jan 31, 2015

AFK right now, but AFAIK .gitignore doesn't support regex but just simple file match patterns. And that is already supported by ctags --exclude.

You are right about the global ignore files. Is also solvable by using full path names in the option but I like the ease of a simple switch.

@blueyed
Copy link
Contributor

blueyed commented Feb 1, 2015

I don't think ctags should add an option for this.
There are many corner cases, and there are several issues with ag about this: https://github.com/ggreer/the_silver_searcher/issues?q=is%3Aissue+is%3Aopen+gitignore.

Instead the tools like ag and git should be used itself to generate the list of files for ctags, e.g.:

ag -l | ctags --links=no -L-

In a similar fashion git ls-files could be used to generate the list.

@jfelchner
Copy link

I agree with @blueyed but not in the same way. I would love this feature. I don't think however that the list of files needs to be piped into ctags. I think a --use-vcs-ignore-file=yes would be more appropriate. Then ctags would look for one and if it finds it, use the appropriate command to generate the exclusions.

For git this would be:

git ls-files --ignored --exclude-standard

The reason I like letting each VCS do the work is because of things like, for example, all the locations that git looks for it's ignore information. It's not just the .gitignore in the current directory. It looks up the tree, in ENV variables, etc, etc. Reproducing this logic in ctags seems like work that doesn't need to be duplicated.

@blueyed
Copy link
Contributor

blueyed commented Jul 1, 2015

@jfelchner
Good idea.
But ctags would then need to detect the VCS type (and not the ignore file), e.g. via git rev-parse --is-inside-work-tree for Git. The ignore file could be in a parent / subdir and might be non-existent (but the global one should still be used then).

@jfelchner
Copy link

@blueyed that's what --exclude-standard does. :) That's what I was saying by not thinking that ctags needed to duplicate all that logic.

@masatake
Copy link
Member

@samaursa, let's reuse this issue here.

The gitignore syntax is not supported.
Someone has to work on this.
I would like to name the option we want --vcs-ignore=git or ... --xignore=git.

Git is so popular. So supporting this feature is important to get the minds of users.
If we can ignore the performance and we don't use seccomp sandbox, using git check-ignore is the fastest way to implement the feature. As the first step we have to make ignore related code modular.

@blueyed
Copy link
Contributor

blueyed commented Mar 31, 2018

For the time being I still recommend to use a wrapper script make-tags (similar to my earlier comment, but using ripgrep now:

#!/bin/sh
rg --files | ctags -R --links=no -L -

@samaursa
Copy link

samaursa commented Mar 31, 2018

@masatake I agree.

@blueyed that is a good interim solution! it works well with plugins with custom command support such as https://github.com/ludovicchabant/vim-gutentags. Thanks!

For anyone who stumbles on this in the future and uses gutentags (or similar plugin), you can do something like this:

let g:gutentags_file_list_command = 'rg --files'

@masatake
Copy link
Member

masatake commented Apr 1, 2018

I'm quite happy if you make a pull request adding the tips (editor neutral part) to

https://github.com/universal-ctags/ctags/blob/master/man/ctags.1.rst.in#L625

.

Adding "TIPS" section is another approach.

Thanks in advance.

@dalance
Copy link

dalance commented Apr 3, 2018

@samaursa
I created a ctags wrapper to support .gitignore.
https://github.com/dalance/ptags

This call git ls-files --ignored --exclude-standard internally as suggested by @jfelchner .

@masatake
Copy link
Member

I have thought "Support for .gitignore in configuration" is a good idea for years.
However, I don't think it should be solved in ctags.
Write libgitignore. We will add code linking the library to ctags.

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

No branches or pull requests

9 participants