diff --git a/README.md b/README.md index 70f97655a1..e2644acf2c 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Use the `linguist-vendored` attribute to vendor or un-vendor paths: ```gitattributes special-vendored-path/* linguist-vendored -jquery.js linguist-vendored=false +jquery.js -linguist-vendored ``` #### Documentation @@ -205,7 +205,7 @@ Use the `linguist-documentation` attribute to mark or unmark paths as documentat ```gitattributes project-docs/* linguist-documentation -docs/formatter.rb linguist-documentation=false +docs/formatter.rb -linguist-documentation ``` #### Generated code @@ -218,7 +218,7 @@ As an added bonus, unlike vendored and documentation files, these files are supp Use the `linguist-generated` attribute to mark or unmark paths as generated. ```gitattributes -Api.elm linguist-generated=true +Api.elm linguist-generated ``` #### Detectable @@ -229,9 +229,9 @@ Languages of a different type (as defined in [`languages.yml`](/lib/linguist/lan Use the `linguist-detectable` attribute to mark or unmark paths as detectable: ```gitattributes -*.kicad_pcb linguist-detectable=true -*.sch linguist-detectable=true -tools/export_bom.py linguist-detectable=false +*.kicad_pcb linguist-detectable +*.sch linguist-detectable +tools/export_bom.py -linguist-detectable ``` ### Using Emacs or Vim modelines diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 389cc24303..98e75efb1f 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -38,24 +38,24 @@ def git_attributes end def documentation? - if attr = git_attributes['linguist-documentation'] - boolean_attribute(attr) + if not git_attributes['linguist-documentation'].nil? + boolean_attribute(git_attributes['linguist-documentation']) else super end end def generated? - if attr = git_attributes['linguist-generated'] - boolean_attribute(attr) + if not git_attributes['linguist-generated'].nil? + boolean_attribute(git_attributes['linguist-generated']) else super end end def vendored? - if attr = git_attributes['linguist-vendored'] - return boolean_attribute(attr) + if not git_attributes['linguist-vendored'].nil? + boolean_attribute(git_attributes['linguist-vendored']) else super end @@ -72,8 +72,8 @@ def language end def detectable? - if attr = git_attributes['linguist-detectable'] - return boolean_attribute(attr) + if not git_attributes['linguist-detectable'].nil? + boolean_attribute(git_attributes['linguist-detectable']) else nil end @@ -100,9 +100,9 @@ def cleanup! protected - # Returns true if the attribute is present and not the string "false". + # Returns true if the attribute is present and not the string "false" and not the false boolean. def boolean_attribute(attribute) - attribute != "false" + attribute != "false" && attribute != false end def load_blob! diff --git a/test/test_repository.rb b/test/test_repository.rb index a9862c11d5..c43d31a3d9 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -55,6 +55,14 @@ def test_repo_git_attributes # test/*.rb linguist-language=Java # Rakefile linguist-generated # test/fixtures/* linguist-vendored=false + # README.md linguist-documentation=false + # samples/Arduino/* linguist-documentation + # samples/Markdown/*.md linguist-detectable=true + # samples/HTML/*.html linguist-detectable=false + # samples/CSS/bootstrap.css -linguist-vendored + # samples/CSS/bootstrap.min.css -linguist-generated + # LICENSE -linguist-documentation + # samples/CoffeeScript/browser.coffee -linguist-detectable attr_commit = 'c20ebee0ebf33f73313d4694680521f80635d477' repo = linguist_repo(attr_commit) @@ -96,47 +104,58 @@ def test_linguist_override_vendored? end def test_linguist_override_unvendored? - attr_commit = 'c20ebee0ebf33f73313d4694680521f80635d477' + attr_commit = '933c687cb8c02035394979b2308e5120a9904fdf' linguist_repo(attr_commit).read_index # lib/linguist/vendor.yml defines this as vendored. override_unvendored = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'test/fixtures/foo.rb') + # test -linguist-vendored attribute method + override_unvendored_minus = Linguist::LazyBlob.new(rugged_repository, attr_commit, 'samples/CSS/bootstrap.css') # overridden .gitattributes - assert !override_unvendored.vendored? + refute override_unvendored.vendored? + refute override_unvendored_minus.vendored? end def test_linguist_override_documentation? - attr_commit = "d4c8fb8a28e91f97a7e53428a365c0abbac36d3d" + attr_commit = "933c687cb8c02035394979b2308e5120a9904fdf" linguist_repo(attr_commit).read_index readme = Linguist::LazyBlob.new(rugged_repository, attr_commit, "README.md") arduino = Linguist::LazyBlob.new(rugged_repository, attr_commit, "samples/Arduino/hello.ino") + # test -linguist-documentation attribute method + minus = Linguist::LazyBlob.new(rugged_repository, attr_commit, "LICENSE") # overridden by .gitattributes refute_predicate readme, :documentation? assert_predicate arduino, :documentation? + refute_predicate minus, :documentation? end def test_linguist_override_generated? - attr_commit = "c20ebee0ebf33f73313d4694680521f80635d477" + attr_commit = "933c687cb8c02035394979b2308e5120a9904fdf" linguist_repo(attr_commit).read_index rakefile = Linguist::LazyBlob.new(rugged_repository, attr_commit, "Rakefile") - + # test -linguist-generated attribute method + minus = Linguist::LazyBlob.new(rugged_repository, attr_commit, "samples/CSS/bootstrap.min.css") # overridden .gitattributes assert rakefile.generated? + refute minus.generated? end def test_linguist_override_detectable? - attr_commit = "8f86998866f6f2c8aa14e0dd430e61fd25cff720" + attr_commit = "933c687cb8c02035394979b2308e5120a9904fdf" linguist_repo(attr_commit).read_index # markdown is overridden by .gitattributes to be detectable, html to not be detectable markdown = Linguist::LazyBlob.new(rugged_repository, attr_commit, "samples/Markdown/tender.md") html = Linguist::LazyBlob.new(rugged_repository, attr_commit, "samples/HTML/pages.html") + # test -linguist-detectable attribute method + minus = Linguist::LazyBlob.new(rugged_repository, attr_commit, "samples/CoffeeScript/browser.coffee") assert_predicate markdown, :detectable? refute_predicate html, :detectable? + refute_predicate minus, :detectable? end end