Skip to content

Commit

Permalink
Adding support for generated overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
arfon committed Sep 3, 2015
1 parent f1383d7 commit 580cfce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/linguist/lazy_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

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)

Expand All @@ -31,22 +35,30 @@ def git_attributes
name, GIT_ATTR, GIT_ATTR_FLAGS)
end

def vendored?
if attr = git_attributes['linguist-vendored']
return boolean_attribute(attr)
def documentation?
if attr = git_attributes['linguist-documentation']
boolean_attribute(attr)
else
return super
super
end
end

def documentation?
if attr = git_attributes['linguist-documentation']
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)

Expand Down
10 changes: 10 additions & 0 deletions test/test_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ def test_linguist_override_documentation?
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

0 comments on commit 580cfce

Please sign in to comment.