mirror of https://github.com/licensee/licensee.git
support for FOO-LICENSE and LICENSE-FOO filenames
This commit is contained in:
parent
4c54b1d12b
commit
e32adecc6e
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
ref: refs/heads/master
|
|
@ -0,0 +1,6 @@
|
|||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
|
@ -0,0 +1,4 @@
|
|||
x<01><>Q
|
||||
à ûí)ö
»k¶Z¥ä&j´b1÷oÚÞ Ãƒyj)¹Y}é-FXèά“a«½ƒ<>ã lÒÍÊ‚iDMb”;úZÌq‡Ùm=6˜|Üÿåç+÷õðC¨å4² !<16>+
|
||||
¢:׳ùQþ±UÞsÏnƒß<C692>z
|
||||
d:x
|
|
@ -0,0 +1,7 @@
|
|||
x]RK‹Ű0îYżbČiĚv·P
|
||||
˝)¶Ľu,#+›ć臫8V°ä†ý÷9É–FŁ™ď5jŰŔËó·/źTŻaĂä¦ŐŁÓđ€‡GBb{~źĚ±÷đĐ>—痯<E28094>ÍŤő„”z:çŚÁ8čő¤›w8NőčuÁaŇěÚľžŽ:oˇßá¬'‡¶ńµÍ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‘”«"`¦B…’JĹă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
|
BIN
test/fixtures/named-license-file-prefix.git/objects/d1/9223f355283b3ce0c51a2c527f685d0f403157
vendored
Normal file
BIN
test/fixtures/named-license-file-prefix.git/objects/d1/9223f355283b3ce0c51a2c527f685d0f403157
vendored
Normal file
Binary file not shown.
BIN
test/fixtures/named-license-file-prefix.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
vendored
Normal file
BIN
test/fixtures/named-license-file-prefix.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
vendored
Normal file
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
643983d3f82ecc2a7d8e4227946220ebffd477d2
|
|
@ -0,0 +1 @@
|
|||
ref: refs/heads/master
|
|
@ -0,0 +1,6 @@
|
|||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
BIN
test/fixtures/named-license-file-suffix.git/objects/36/465372136f81a2089f486298ca77ef41611198
vendored
Normal file
BIN
test/fixtures/named-license-file-suffix.git/objects/36/465372136f81a2089f486298ca77ef41611198
vendored
Normal file
Binary file not shown.
|
@ -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<>fم<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غ
|
|
@ -0,0 +1,7 @@
|
|||
x]RK‹Ű0îYżbČiĚv·P
|
||||
˝)¶Ľu,#+›ć臫8V°ä†ý÷9É–FŁ™ď5jŰŔËó·/źTŻaĂä¦ŐŁÓđ€‡GBb{~źĚ±÷đĐ>—痯<E28094>ÍŤő„”z:çŚÁ8čő¤›w8NőčuÁaŇěÚľžŽ:oˇßá¬'‡¶ńµÍ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‘”«"`¦B…’JĹă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
|
BIN
test/fixtures/named-license-file-suffix.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
vendored
Normal file
BIN
test/fixtures/named-license-file-suffix.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
vendored
Normal file
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
4a2a139e7fbd24eef5c5ef3d22f490e89405f6a3
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue