Override languages being included by language statistics (#3807)

* Add detectable key to languages

This key allows to override the language being included in the
language stats of a repository.

* Make detectable override-able using .gitattributes

* Mention `linguist-detectable` in README

* Remove detectable key from languages

Reverts changes in 0f7c0df5.

* Update commit hash to the one that was merged

PR #3806 changed the commit hash. The original commit was not
actually merged into the test/attributes branch.

* Fix check to ensure detectable is defined

* Add include in language stats tests when detectable set

* Ignore detectable when vendored, documentation or overridden

* Add documentation on detectable override in README

* Improve documentation on detectable override in README
This commit is contained in:
Seppe Stas
2018-01-23 13:17:48 +01:00
committed by Colin Seymour
parent fef7a12c85
commit 8da6ddf9d9
5 changed files with 71 additions and 3 deletions

View File

@@ -307,5 +307,36 @@ class TestBlob < Minitest::Test
included = sample_blob_memory("HTML/pages.html")
assert_predicate included, :include_in_language_stats?
# Test detectable override (i.e by .gitattributes)
def prose.detectable?; true end
assert_predicate prose, :include_in_language_stats?
included_not_detectable = included.clone()
def included_not_detectable.detectable?; false end
refute_predicate included_not_detectable, :include_in_language_stats?
# Test not included if vendored, documentation or generated overridden
# even if detectable
included_vendored = included.clone()
def included_vendored.vendored?; true end
refute_predicate included_vendored, :include_in_language_stats?
def included_vendored.detectable?; true end
refute_predicate included_vendored, :include_in_language_stats?
included_documentation = included.clone()
def included_documentation.documentation?; true end
refute_predicate included_documentation, :include_in_language_stats?
def included_documentation.detectable?; true end
refute_predicate included_documentation, :include_in_language_stats?
included_generated = included.clone()
def included_generated.generated?; true end
refute_predicate included_generated, :include_in_language_stats?
def included_generated.detectable?; true end
refute_predicate included_generated, :include_in_language_stats?
end
end

View File

@@ -121,4 +121,16 @@ class TestRepository < Minitest::Test
# overridden .gitattributes
assert rakefile.generated?
end
def test_linguist_override_detectable?
attr_commit = "8f86998866f6f2c8aa14e0dd430e61fd25cff720"
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")
assert_predicate markdown, :detectable?
refute_predicate html, :detectable?
end
end