create: Fix getting name from GitHub archives
`brew create https://github.com/lapce/lapce/archive/v0.3.0.tar.gz` was getting the wrong name 'v3.0.0' from the URL Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
fcfce58973
commit
6afd15ae00
@ -172,13 +172,12 @@ module Homebrew
|
|||||||
fetch: !args.no_fetch?,
|
fetch: !args.no_fetch?,
|
||||||
head: args.HEAD?,
|
head: args.HEAD?,
|
||||||
)
|
)
|
||||||
if fc.name.blank?
|
|
||||||
stem = Pathname.new(args.named.first).stem.rpartition("=").last
|
|
||||||
print "Formula name [#{stem}]: "
|
|
||||||
fc.name = __gets || stem
|
|
||||||
end
|
|
||||||
|
|
||||||
fc.parse_url
|
fc.parse_url
|
||||||
|
# ask for confirmation if name wasn't passed explicitly
|
||||||
|
if args.set_name.blank?
|
||||||
|
print "Formula name [#{fc.name}]: "
|
||||||
|
fc.name = __gets || fc.name
|
||||||
|
end
|
||||||
|
|
||||||
fc.verify
|
fc.verify
|
||||||
|
|
||||||
|
@ -31,25 +31,37 @@ module Homebrew
|
|||||||
raise TapUnavailableError, @tap.name unless @tap.installed?
|
raise TapUnavailableError, @tap.name unless @tap.installed?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.name_from_url(url)
|
||||||
|
stem = Pathname.new(url).stem
|
||||||
|
# special cases first
|
||||||
|
if stem.start_with? "index.cgi"
|
||||||
|
# gitweb URLs e.g. http://www.codesrc.com/gitweb/index.cgi?p=libzipper.git;a=summary
|
||||||
|
stem.rpartition("=").last
|
||||||
|
elsif url =~ %r{github\.com/\S+/(\S+)/(archive|releases)/}
|
||||||
|
# e.g. https://github.com/stella-emu/stella/releases/download/6.7/stella-6.7-src.tar.xz
|
||||||
|
Regexp.last_match(1)
|
||||||
|
else
|
||||||
|
# e.g. http://digit-labs.org/files/tools/synscan/releases/synscan-5.02.tar.gz
|
||||||
|
pathver = Version.parse(stem).to_s
|
||||||
|
stem.sub(/[-_.]?#{Regexp.escape(pathver)}$/, "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def parse_url
|
def parse_url
|
||||||
path = Pathname.new(@url)
|
@name = FormulaCreator.name_from_url(@url) if @name.blank?
|
||||||
if @name.nil?
|
odebug "name_from_url: #{@name}"
|
||||||
|
@version = Version.detect(@url) if @version.nil?
|
||||||
|
|
||||||
case @url
|
case @url
|
||||||
when %r{github\.com/(\S+)/(\S+)\.git}
|
when %r{github\.com/(\S+)/(\S+)\.git}
|
||||||
@user = Regexp.last_match(1)
|
@user = Regexp.last_match(1)
|
||||||
@name = Regexp.last_match(2)
|
|
||||||
@head = true
|
@head = true
|
||||||
@github = true
|
@github = true
|
||||||
when %r{github\.com/(\S+)/(\S+)/(archive|releases)/}
|
when %r{github\.com/(\S+)/(\S+)/(archive|releases)/}
|
||||||
@user = Regexp.last_match(1)
|
@user = Regexp.last_match(1)
|
||||||
@name = Regexp.last_match(2)
|
|
||||||
@github = true
|
@github = true
|
||||||
else
|
|
||||||
@name = path.basename.to_s[/(.*?)[-_.]?#{Regexp.escape(path.version.to_s)}/, 1]
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@version = Version.detect(@url) if @version.nil?
|
|
||||||
end
|
|
||||||
|
|
||||||
def write_formula!
|
def write_formula!
|
||||||
raise ArgumentError, "name is blank!" if @name.blank?
|
raise ArgumentError, "name is blank!" if @name.blank?
|
||||||
|
30
Library/Homebrew/test/formula_creator_spec.rb
Normal file
30
Library/Homebrew/test/formula_creator_spec.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require "formula_creator"
|
||||||
|
|
||||||
|
describe Homebrew::FormulaCreator do
|
||||||
|
it "gets name from GitHub archive URL" do
|
||||||
|
t = described_class.name_from_url("https://github.com/abitrolly/lapce/archive/v0.3.0.tar.gz")
|
||||||
|
expect(t).to eq("lapce")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "gets name from gitweb URL" do
|
||||||
|
t = described_class.name_from_url("http://www.codesrc.com/gitweb/index.cgi?p=libzipper.git;a=summary")
|
||||||
|
expect(t).to eq("libzipper")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "gets name from GitHub repo URL" do
|
||||||
|
t = described_class.name_from_url("https://github.com/abitrolly/lapce.git")
|
||||||
|
expect(t).to eq("lapce")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "gets name from GitHub download URL" do
|
||||||
|
t = described_class.name_from_url("https://github.com/stella-emu/stella/releases/download/6.7/stella-6.7-src.tar.xz")
|
||||||
|
expect(t).to eq("stella")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "gets name from generic tarball URL" do
|
||||||
|
t = described_class.name_from_url("http://digit-labs.org/files/tools/synscan/releases/synscan-5.02.tar.gz")
|
||||||
|
expect(t).to eq("synscan")
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user