Fix Homebrew/homebrew#52: Add ability to checkout a branch or tag.
GitDownloadStrategy and MercurialDownloadStrategy now can be used like this: head 'git://server/repo.git', :branch => 'stable' head 'hg://server/repo/', :tag => '1.0.4'
This commit is contained in:
parent
53d6f617d7
commit
ef02031d7c
@ -22,8 +22,15 @@
|
||||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
class AbstractDownloadStrategy
|
||||
def initialize url, name, version
|
||||
def initialize url, name, version, specs
|
||||
@url=url
|
||||
case specs
|
||||
when Hash
|
||||
@spec = specs.keys.first # only use first spec
|
||||
@ref = specs.values.first
|
||||
else
|
||||
spec = nil
|
||||
end
|
||||
@unique_token="#{name}-#{version}" unless name.to_s.empty? or name == '__UNKNOWN__'
|
||||
end
|
||||
end
|
||||
@ -131,8 +138,17 @@ class GitDownloadStrategy <AbstractDownloadStrategy
|
||||
end
|
||||
end
|
||||
def stage
|
||||
dst=Dir.getwd
|
||||
dst = Dir.getwd
|
||||
Dir.chdir @clone do
|
||||
if @spec and @ref
|
||||
ohai "Checking out #{@spec} #{@ref}"
|
||||
case @spec
|
||||
when :branch
|
||||
safe_system 'git', 'checkout', '-b', @ref, "origin/#{@ref}"
|
||||
when :tag
|
||||
safe_system 'git', 'checkout', @ref
|
||||
end
|
||||
end
|
||||
# http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export
|
||||
safe_system 'git', 'checkout-index', '-af', "--prefix=#{dst}/"
|
||||
end
|
||||
@ -200,7 +216,14 @@ class MercurialDownloadStrategy <AbstractDownloadStrategy
|
||||
def stage
|
||||
dst=Dir.getwd
|
||||
Dir.chdir @clone do
|
||||
safe_system 'hg', 'archive', '-y', '-t', 'files', dst
|
||||
if @spec and @ref
|
||||
ohai "Checking out #{@spec} #{@ref}"
|
||||
Dir.chdir @clone do
|
||||
safe_system 'hg', 'archive', '-y', '-r', @ref, '-t', 'files', dst
|
||||
end
|
||||
else
|
||||
safe_system 'hg', 'archive', '-y', '-t', 'files', dst
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -46,6 +46,7 @@ class Formula
|
||||
def initialize name='__UNKNOWN__'
|
||||
set_instance_variable 'url'
|
||||
set_instance_variable 'head'
|
||||
set_instance_variable 'specs'
|
||||
|
||||
if @head and (not @url or ARGV.flag? '--HEAD')
|
||||
@url=@head
|
||||
@ -85,7 +86,7 @@ class Formula
|
||||
self.class.path name
|
||||
end
|
||||
|
||||
attr_reader :url, :version, :homepage, :name
|
||||
attr_reader :url, :version, :homepage, :name, :specs
|
||||
|
||||
def bin; prefix+'bin' end
|
||||
def sbin; prefix+'sbin' end
|
||||
@ -281,7 +282,7 @@ private
|
||||
end
|
||||
|
||||
def stage
|
||||
ds=download_strategy.new url, name, version
|
||||
ds=download_strategy.new url, name, version, specs
|
||||
HOMEBREW_CACHE.mkpath
|
||||
dl=ds.fetch
|
||||
verify_download_integrity dl if dl.kind_of? Pathname
|
||||
@ -380,7 +381,14 @@ private
|
||||
end
|
||||
end
|
||||
|
||||
attr_rw :url, :version, :homepage, :head, :deps, *CHECKSUM_TYPES
|
||||
attr_rw :url, :version, :homepage, :specs, :deps, *CHECKSUM_TYPES
|
||||
|
||||
def head val=nil, specs=nil
|
||||
if specs
|
||||
@specs = specs
|
||||
end
|
||||
val.nil? ? @head : @head = val
|
||||
end
|
||||
|
||||
def depends_on name, *args
|
||||
@deps ||= []
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user