support for FOO-LICENSE and LICENSE-FOO filenames

This commit is contained in:
Ben Balter 2015-02-27 16:12:48 -05:00
parent 4c54b1d12b
commit e32adecc6e
16 changed files with 54 additions and 4 deletions

View File

@ -32,11 +32,14 @@ class Licensee
return @license_file if defined? @license_file
commit = @revision ? @repository.lookup(@revision) : @repository.last_commit
license_blob = commit.tree.each_blob { |blob| break blob if LICENSE_FILENAMES.include? blob[:name].downcase }
@license_file = if license_blob
LicenseFile.new(@repository.lookup(license_blob[:oid]))
end
# Prefer an exact match to one of our known file names
license_blob = commit.tree.find { |blob| LICENSE_FILENAMES.include? blob[:name].downcase }
# Fall back to the first file in the project root that has the word license in it
license_blob = commit.tree.find { |blob| blob[:name] =~ /license/i } unless license_blob
@license_file = LicenseFile.new(@repository.lookup(license_blob[:oid])) if license_blob
end
# Returns the matching Licensee::License instance if a license can be detected

View File

@ -0,0 +1 @@
ref: refs/heads/master

View File

@ -0,0 +1,6 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
precomposeunicode = true

View File

@ -0,0 +1,4 @@
x<01><>Q
à ûí)ö »k¶Z¥ä&j´b1÷oÚÞ Ãyj)¹Y}é-FXèά“a«½ƒ<>ã lÒÍÊiDMb”;úZÌq‡Ùm=6˜ÿåç+÷õðC¨å !<16>+
¢:׳ùQþ±UÞsÏnƒß<C692>z
d:x

View File

@ -0,0 +1,7 @@
x]RKŰ0îYżbČiĚv·P
˝)¶Ľu,#+›ć臫8V°ä†ý÷ FŁ™ď5jŰŔËó·/źTŻaĂä¦ŐŁÓđ€‡GBb{~źĚ±÷đĐ>—痯<E28094>ÍŤő„”z:çŚÁ8čő¤w8NőčuÁaŇěÚľžŽ:ßá¬'‡¶ńµÍx„Zd Řé{„qöŕ/ő¤±ą<C2B1>Ú9Űšń łí|ŇŁŻ}ŕ;<3B>A;xđ(yUÝ&VŹ I§ë<C2A7><C3AB>Ń4ÜŻŕb|og“v~2mŔ<6D>ŔŚí0wAĂýz0'scămGPůěĐAĐÁÉvćţz±užÁ¸>‚ÎčföŘéBqI1
>>Ű śu/^˙Ş[zB><3E> ňß"rˇréíé_'Ć‘Ă<ŤH‰ˇ`Gg1˛…ń—n}¨ĺ; ö¬µvěLđ뾢đŞněo˝xąnu´Ą.q/ XD\·z»r}= Đč[`ČńbéĂş›çqń¦ŕl§…ďOČź1¨DŞvT2ŕ”RĽń„%°˘žWě¸ĘÄVvHZ¨=<3D>h±‡ĽH"`?KÉŞ
„$|SćśaŤqľMxń
kś+>`Ž/A•€@x<>â çRŘ0g<>L×<çj‘”«"`¦BJĹămN%”[YŠŠ!}‚°/R‰,lĂ
ő„¬Xö†¨2šç<C5A1>ŠĐ-Ş—AĢÜKţš)ČDž0,®*Łëś]©ĐTśSľ‰ ˇúÔI<10>"Ih»Ş<C2BB>]ĆB)đQübĹElĢPŹş”ęctÇ+•Ľ
<EFBFBD>¤Rl"âÄ DGś+Ř%D˝ô±l <09>mŃô] $Ść<C59A>…ë)‹÷ć'ň‰ˇW

View File

@ -0,0 +1 @@
643983d3f82ecc2a7d8e4227946220ebffd477d2

View File

@ -0,0 +1 @@
ref: refs/heads/master

View File

@ -0,0 +1,6 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
precomposeunicode = true

View File

@ -0,0 +1,3 @@
x<01><>[
أ D<>ٍ*َ<1A><><03><>ٌDE!*بح<D8A8>k<EFBFBD><1D>g8 <0C><>ظk-ول<D988>FJ <20>2ZZ<5A>زd<D8B2>^p<><66>X]<5D>ض<EFBFBD>،ذ قي<D982>؟وو<03>ش`<60>'<27>[Hm _~<7E>
WXb<58>@%4<>3 <0A><>ن<EFBFBD>حv~~<7E>lVZ<56>قO<D982>ح<EFBFBD>7<EFBFBD>19غ

View File

@ -0,0 +1,7 @@
x]RKŰ0îYżbČiĚv·P
˝)¶Ľu,#+›ć臫8V°ä†ý÷ FŁ™ď5jŰŔËó·/źTŻaĂä¦ŐŁÓđ€‡GBb{~źĚ±÷đĐ>—痯<E28094>ÍŤő„”z:çŚÁ8čő¤w8NőčuÁaŇěÚľžŽ:ßá¬'‡¶ńµÍx„Zd Řé{„qöŕ/ő¤±ą<C2B1>Ú9Űšń łí|ŇŁŻ}ŕ;<3B>A;xđ(yUÝ&VŹ I§ë<C2A7><C3AB>Ń4ÜŻŕb|og“v~2mŔ<6D>ŔŚí0wAĂýz0'scămGPůěĐAĐÁÉvćţz±užÁ¸>‚ÎčföŘéBqI1
>>Ű śu/^˙Ş[zB><3E> ňß"rˇréíé_'Ć‘Ă<ŤH‰ˇ`Gg1˛…ń—n}¨ĺ; ö¬µvěLđ뾢đŞněo˝xąnu´Ą.q/ XD\·z»r}= Đč[`ČńbéĂş›çqń¦ŕl§…ďOČź1¨DŞvT2ŕ”RĽń„%°˘žWě¸ĘÄVvHZ¨=<3D>h±‡ĽH"`?KÉŞ
„$|SćśaŤqľMxń
kś+>`Ž/A•€@x<>â çRŘ0g<>L×<çj‘”«"`¦BJĹămN%”[YŠŠ!}‚°/R‰,lĂ
ő„¬Xö†¨2šç<C5A1>ŠĐ-Ş—AĢÜKţš)ČDž0,®*Łëś]©ĐTśSľ‰ ˇúÔI<10>"Ih»Ş<C2BB>]ĆB)đQübĹElĢPŹş”ęctÇ+•Ľ
<EFBFBD>¤Rl"âÄ DGś+Ř%D˝ô±l <09>mŃô] $Ść<C59A>…ë)‹÷ć'ň‰ˇW

View File

@ -0,0 +1 @@
4a2a139e7fbd24eef5c5ef3d22f490e89405f6a3

View File

@ -18,4 +18,14 @@ class TestLicenseeProject < Minitest::Test
project = Licensee::Project.new fixture_path("case-sensitive.git")
assert_equal Licensee::LicenseFile, project.license_file.class
end
should "detect MIT-LICENSE licensed projects" do
project = Licensee::Project.new fixture_path("named-license-file-prefix.git")
assert_equal "mit", project.license.key
end
should "detect LICENSE-MIT licensed projects" do
project = Licensee::Project.new fixture_path("named-license-file-suffix.git")
assert_equal "mit", project.license.key
end
end