From 580cfce7fbd1d7d3dbb06ab9a7fdea54c6527797 Mon Sep 17 00:00:00 2001 From: Arfon Smith Date: Thu, 3 Sep 2015 14:39:27 +0100 Subject: [PATCH] Adding support for generated overrides --- lib/linguist/lazy_blob.rb | 30 +++++++++++++++++++++--------- test/test_repository.rb | 10 ++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index 78f37b18..55c10309 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -4,7 +4,11 @@ require 'rugged' module Linguist class LazyBlob - GIT_ATTR = ['linguist-documentation', 'linguist-language', 'linguist-vendored'] + GIT_ATTR = ['linguist-documentation', + 'linguist-language', + 'linguist-vendored', + 'linguist-generated'] + GIT_ATTR_OPTS = { :priority => [:index], :skip_system => true } GIT_ATTR_FLAGS = Rugged::Repository::Attributes.parse_opts(GIT_ATTR_OPTS) @@ -31,14 +35,6 @@ module Linguist name, GIT_ATTR, GIT_ATTR_FLAGS) end - def vendored? - if attr = git_attributes['linguist-vendored'] - return boolean_attribute(attr) - else - return super - end - end - def documentation? if attr = git_attributes['linguist-documentation'] boolean_attribute(attr) @@ -47,6 +43,22 @@ module Linguist end end + def generated? + if attr = git_attributes['linguist-generated'] + boolean_attribute(attr) + else + super + end + end + + def vendored? + if attr = git_attributes['linguist-vendored'] + return boolean_attribute(attr) + else + super + end + end + def language return @language if defined?(@language) diff --git a/test/test_repository.rb b/test/test_repository.rb index fcdd4f0c..a1f9fc86 100644 --- a/test/test_repository.rb +++ b/test/test_repository.rb @@ -111,4 +111,14 @@ class TestRepository < Minitest::Test refute_predicate readme, :documentation? assert_predicate arduino, :documentation? end + + def test_linguist_override_generated? + attr_commit = "351c1cc8fd57340839bdb400d7812332af80e9bd" + repo = linguist_repo(attr_commit).read_index + + rakefile = Linguist::LazyBlob.new(rugged_repository, attr_commit, "Rakefile") + + # overridden .gitattributes + assert rakefile.generated? + end end