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

gitattributes seems not to be used #4050

Closed
4 tasks done
pawamoy opened this issue Mar 1, 2018 · 10 comments
Closed
4 tasks done

gitattributes seems not to be used #4050

pawamoy opened this issue Mar 1, 2018 · 10 comments

Comments

@pawamoy
Copy link

pawamoy commented Mar 1, 2018

Preliminary Steps

Please confirm you have...

Problem Description

So it says Linguist takes into account any override. I tried locally to override *.1 files to be detected as "vendored" or "documentation", using .gitattributes (in order to get rid of them in the stats), but it does not work.

I tried many different combinations:
*.1 linguist-vendored, *.1 linguist-vendored=true, *.1 linguist-documentation, licenses/* linguist-vendored, but my code is always reported as being 86.12% Roff.

$ cat .gitattributes 
licenses/* linguist-vendored

$ linguist . --breakdown
86.12%  Roff
13.88%  Python

Python:
hooks/post_gen_project.py
setup.py
specs/support/runner.py
specs/support/settings.py
specs/template_spec.py
{{cookiecutter.repository_name}}/hooks/post_gen_project.py

Roff:
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.1
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.2
{{cookiecutter.repository_name}}/licenses/GNU_Lesser_General_Public_License_v2.1
{{cookiecutter.repository_name}}/licenses/SIL_Open_Font_License_1.1

URL of the affected repository:

https://github.com/Pawamoy/cookiecutter-cookiecutter

Last modified on:

Not relevant. It's not even working locally. I have installed linguist version 6.0.1 with gem install github-linguist through rbenv, ruby version 2.4.0.

Expected language:

It would be better if the licenses text were detected as text, but this is not the issue here, since I am responsible for having named the files with a .1 extension (as in European_Union_Public_License_1.1). I don't mind that.

Detected language:

Roff, which is fine.

@Alhadis
Copy link
Collaborator

Alhadis commented Mar 1, 2018

Try pushing a minor change to one of those license files. GitHub caches each repository's language breakdown, which means changes to .gitattributes files won't become visible until after the next push.

@pawamoy
Copy link
Author

pawamoy commented Mar 1, 2018

Yes I understand that, but I'm trying to do this locally, not to see the changes on GitHub.

@Alhadis
Copy link
Collaborator

Alhadis commented Mar 1, 2018

Does *.1 linguist-language=Text work?

@pawamoy
Copy link
Author

pawamoy commented Mar 1, 2018

No 😂 Still detected as Roff!

@lildude
Copy link
Member

lildude commented Mar 1, 2018

Two things:

  1. your override won't match as licenses is not in the root of your repo
  2. you need to commit your .gitattributes for it to take effect
$ linguist --breakdown
86.12%  Roff
13.88%  Python

Python:
hooks/post_gen_project.py
setup.py
specs/support/runner.py
specs/support/settings.py
specs/template_spec.py
{{cookiecutter.repository_name}}/hooks/post_gen_project.py

Roff:
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.1
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.2
{{cookiecutter.repository_name}}/licenses/GNU_Lesser_General_Public_License_v2.1
{{cookiecutter.repository_name}}/licenses/SIL_Open_Font_License_1.1

[lildude-MBP : ...cookiecutter-cookiecutter (master)]$ echo "licenses/* linguist-vendored" > .gitattributes
[lildude-MBP : ...ookiecutter-cookiecutter (master●)]$ linguist --breakdown
86.12%  Roff
13.88%  Python

Python:
hooks/post_gen_project.py
setup.py
specs/support/runner.py
specs/support/settings.py
specs/template_spec.py
{{cookiecutter.repository_name}}/hooks/post_gen_project.py

Roff:
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.1
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.2
{{cookiecutter.repository_name}}/licenses/GNU_Lesser_General_Public_License_v2.1
{{cookiecutter.repository_name}}/licenses/SIL_Open_Font_License_1.1

[lildude-MBP : ...ookiecutter-cookiecutter (master●)]$ git add .gitattributes
[lildude-MBP : ...ookiecutter-cookiecutter (master●)]$ git commit -m 'Add attribs'
[master 0062a89] Add attribs
 1 file changed, 1 insertion(+)
 create mode 100644 .gitattributes
[lildude-MBP : ...cookiecutter-cookiecutter (master)]$ linguist --breakdown 
86.12%  Roff
13.88%  Python

Python:
hooks/post_gen_project.py
setup.py
specs/support/runner.py
specs/support/settings.py
specs/template_spec.py
{{cookiecutter.repository_name}}/hooks/post_gen_project.py

Roff:
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.1
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.2
{{cookiecutter.repository_name}}/licenses/GNU_Lesser_General_Public_License_v2.1
{{cookiecutter.repository_name}}/licenses/SIL_Open_Font_License_1.1

[lildude-MBP : ...cookiecutter-cookiecutter (master)]$ echo "*/licenses/* linguist-vendored" >! .gitattributes
[lildude-MBP : ...ookiecutter-cookiecutter (master●)]$ git commit -am 'Update attribs'
[master 20791da] Update attribs
 1 file changed, 1 insertion(+), 1 deletion(-)
[lildude-MBP : ...cookiecutter-cookiecutter (master)]$ linguist --breakdown
100.00% Python

Python:
hooks/post_gen_project.py
setup.py
specs/support/runner.py
specs/support/settings.py
specs/template_spec.py
{{cookiecutter.repository_name}}/hooks/post_gen_project.py

[lildude-MBP : ...cookiecutter-cookiecutter (master)]$ echo "*.1 linguist-vendored" >! .gitattributes
[lildude-MBP : ...ookiecutter-cookiecutter (master●)]$ git commit -am 'Update attribs'
[master 8d27937] Update attribs
 1 file changed, 1 insertion(+), 1 deletion(-)
[lildude-MBP : ...cookiecutter-cookiecutter (master)]$ linguist --breakdown
59.96%  Roff
40.04%  Python

Python:
hooks/post_gen_project.py
setup.py
specs/support/runner.py
specs/support/settings.py
specs/template_spec.py
{{cookiecutter.repository_name}}/hooks/post_gen_project.py

Roff:
{{cookiecutter.repository_name}}/licenses/European_Union_Public_License_1.2

[lildude-MBP : ...cookiecutter-cookiecutter (master)]$

@pchaigno
Copy link
Contributor

pchaigno commented Mar 1, 2018

A single asterisk before /licenses/ works if you're sure licenses is in a subdirectory. If it may be deeper in the hierarchy of directories, you'll need two wildcards:

**/licenses/* linguist-vendored

@pawamoy
Copy link
Author

pawamoy commented Mar 1, 2018

So, the important points:

  • .gitattributes must be committed again after each modification for linguist to take it into account,
  • patterns in .gitattributes are not magically matched against whole path of a file, we need to use wildcards when necessary.

Would a PR adding these two points in the related README section be accepted?

Thank you @lildude, @pchaigno and @Alhadis!

@pawamoy pawamoy closed this as completed Mar 1, 2018
@Alhadis
Copy link
Collaborator

Alhadis commented Mar 1, 2018

Also note that a pattern like licenses/ won't work, it needs a trailing asterisk: licenses/*.

This is unlike a .gitignore file, where entire directories can be marked by specifying the directory name, rather than a globbing pattern:

# .gitignore
path/to/folder      # Works
path/to/folder/*    # Works

# .gitattributes
path/to/folder      # Doesn't work
path/to/folder/*    # Works

@pchaigno
Copy link
Contributor

pchaigno commented Mar 1, 2018

Would a PR adding these two points in the related README section be accepted?

👍 for me. The second point is not specific to Linguist tough. Maybe point to the appropriate documentation and change one of the examples to show a more complex case (e.g., **/dir/*)?

@pawamoy
Copy link
Author

pawamoy commented Mar 1, 2018

Indeed it's not specific to linguist, a simple reminder + doc link + example would be good enough. Let's see that in a PR :)

@github-linguist github-linguist locked as resolved and limited conversation to collaborators Jun 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants