linguist-generated
override not working properly.
#5308
-
Describe the bug
# .gitattributes
# Ignore these files for PR and some other processes.
# Based on https://docs.github.com/en/github/administering-a-repository/customizing-how-changed-files-appear-on-github
# Guide: https://github.com/github/linguist
# Protobuf
gui/src/protobuf/truera/protobuf/* linguist-generated
gui/src/protobuf/truera/protobuf/public/model_pb.d.ts linguist-generated
python/truera/protobuf/* linguist-generated
# OpenAPI
python/truera/modelrunner/client/* linguist-generated
gui/src/network/mrc/src/ linguist-generated
gui/package-lock.json linguist-generated Expected behaviourLinguist for Actual behaviour: $ github-linguist gui/src/protobuf/truera/protobuf/public/model_pb.d.ts
model_pb.d.ts: 156 lines (139 sloc)
type: Text
mime type: video/MP2T
language: TypeScript
appears to be a vendored file Some files are marked as generated though: $ github-linguist gui/package-lock.json
package-lock.json: 0 lines (0 sloc)
type: Text
mime type: application/json
language: JSON
blob is too large to be shown
appears to be generated source code Additional notesVersion: $ github-linguist --version
Linguist v5.3.3
Detect language type for a file, or, given a repository, determine language breakdown.
Usage: linguist <path>
linguist <path> [--breakdown] [--json]
linguist [--breakdown] [--json] |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Directly querying a file using When querying the repo as a whole, Linguist uses the When it comes to checking whether a file is vendored or generated, Linguist (actually rugged) will query in the order listed: ... which as you can see, shows vendored before generated. As your file is considered vendored by Linguist here: ... it'll use that and not continue onto testing if it is generated as neither count towards the stats. Thus, if you wish for the file to be considered generated and not vendored, you'll need to mark it is "unvendored" and generated in the override, eg:
This won't adjust the CLI output, but it will be considered when analysed as part of querying the repo as a whole as happens on github.com. So in summary, the |
Beta Was this translation helpful? Give feedback.
-
Hi @lildude, thanks for the detailed explanation.
Based on your explanation, the override shouldnt work from the command line, but github should be picking them as generated though, any advice on why that would be? Could it be caused by the syntax difference? |
Beta Was this translation helpful? Give feedback.
-
Nope. It makes no difference.
The override won't show as taking effect when querying the first specifically from the CLI, but it will be considered when checking the repo as a whole from the CLI. ie $ echo "foo" > gui/src/protobuf/truera/protobuf/version_pb.js
$ echo "foo" > gui/src/protobuf/truera/protobuf/public/another.js
$ git add .
$ git commit -am 'Add more'
[main 4c2d658] Add more
2 files changed, 2 insertions(+)
create mode 100644 gui/src/protobuf/truera/protobuf/public/another.js
create mode 100644 gui/src/protobuf/truera/protobuf/version_pb.js
$ github-linguist .
100.00% JavaScript
$ github-linguist . --breakdown
100.00% JavaScript
JavaScript:
gui/src/protobuf/truera/protobuf/public/another.js
gui/src/protobuf/truera/protobuf/version_pb.js
$ echo 'gui/src/protobuf/truera/protobuf/* linguist-generated' >> .gitattributes
$ git add .gitattributes
$ git commit -m 'Add override'
[main 9297f01] Add override
1 file changed, 1 insertion(+)
$ github-linguist . --breakdown
100.00% JavaScript
JavaScript:
gui/src/protobuf/truera/protobuf/public/another.js
$ You can also confirm your override is taking effect by taking Linguist out of the equation entirely by querying the attributes with git: $ git check-attr linguist-generated gui/src/protobuf/truera/protobuf/version_pb.js
gui/src/protobuf/truera/protobuf/version_pb.js: linguist-generated: set ### <--- Indicates the override is set so will take effect
$ git check-attr linguist-generated gui/src/protobuf/truera/protobuf/public/another.js
gui/src/protobuf/truera/protobuf/public/another.js: linguist-generated: unspecified
$ So, if you've committed your overrides as reported in the OP to the repo (the file must be committed for Linguist to use it), it should be detected as generated as it would be covered by this override rule which applies to all files in that directory, but not within subdirectories as I've illustrated:
This rule doesn't apply to files in subdirectories because it's not recursive. For that you need to use How are you determining your override isn't taking effect? Do you have a repo that I can see this in action? |
Beta Was this translation helpful? Give feedback.
-
Oh yes, and you're running a very very old version of Linguist locally. I recommend you upgrade to the latest to be sure you're getting the same behaviour locally as on github.com. The latest is v7.13.0. |
Beta Was this translation helpful? Give feedback.
-
At this isn't a bug, I'm also moving this to discussions. |
Beta Was this translation helpful? Give feedback.
Directly querying a file using
github-linguist
doesn't honour the overrides in.gitattributes
as it doesn't pull in all the repo information and callsvendored?
from theblob_helper.rb
directly which doesn't pull in the overrides:https://github.com/github/linguist/blob/a3de9b8d54d0b10c41ed80ab2ee9c4bef45c49da/lib/linguist/blob_helper.rb#L219-L232
When querying the repo as a whole, Linguist uses the
vendored?
fromlazy_blob.rb
which does honour overrides:https://github.com/github/linguist/blob/a3de9b8d54d0b10c41ed80ab2ee9c4bef45c49da/lib/linguist/lazy_blob.rb#L56-L62
When it comes to checking whether a file is vendored or generated, Linguist (actually rugged) will query in the order listed: