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.
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
class AbstractDownloadStrategy
|
class AbstractDownloadStrategy
|
||||||
def initialize url, name, version
|
def initialize url, name, version, specs
|
||||||
@url=url
|
@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__'
|
@unique_token="#{name}-#{version}" unless name.to_s.empty? or name == '__UNKNOWN__'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -131,8 +138,17 @@ class GitDownloadStrategy <AbstractDownloadStrategy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def stage
|
def stage
|
||||||
dst=Dir.getwd
|
dst = Dir.getwd
|
||||||
Dir.chdir @clone do
|
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
|
# http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export
|
||||||
safe_system 'git', 'checkout-index', '-af', "--prefix=#{dst}/"
|
safe_system 'git', 'checkout-index', '-af', "--prefix=#{dst}/"
|
||||||
end
|
end
|
||||||
@ -200,7 +216,14 @@ class MercurialDownloadStrategy <AbstractDownloadStrategy
|
|||||||
def stage
|
def stage
|
||||||
dst=Dir.getwd
|
dst=Dir.getwd
|
||||||
Dir.chdir @clone do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -46,6 +46,7 @@ class Formula
|
|||||||
def initialize name='__UNKNOWN__'
|
def initialize name='__UNKNOWN__'
|
||||||
set_instance_variable 'url'
|
set_instance_variable 'url'
|
||||||
set_instance_variable 'head'
|
set_instance_variable 'head'
|
||||||
|
set_instance_variable 'specs'
|
||||||
|
|
||||||
if @head and (not @url or ARGV.flag? '--HEAD')
|
if @head and (not @url or ARGV.flag? '--HEAD')
|
||||||
@url=@head
|
@url=@head
|
||||||
@ -85,7 +86,7 @@ class Formula
|
|||||||
self.class.path name
|
self.class.path name
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :url, :version, :homepage, :name
|
attr_reader :url, :version, :homepage, :name, :specs
|
||||||
|
|
||||||
def bin; prefix+'bin' end
|
def bin; prefix+'bin' end
|
||||||
def sbin; prefix+'sbin' end
|
def sbin; prefix+'sbin' end
|
||||||
@ -281,7 +282,7 @@ private
|
|||||||
end
|
end
|
||||||
|
|
||||||
def stage
|
def stage
|
||||||
ds=download_strategy.new url, name, version
|
ds=download_strategy.new url, name, version, specs
|
||||||
HOMEBREW_CACHE.mkpath
|
HOMEBREW_CACHE.mkpath
|
||||||
dl=ds.fetch
|
dl=ds.fetch
|
||||||
verify_download_integrity dl if dl.kind_of? Pathname
|
verify_download_integrity dl if dl.kind_of? Pathname
|
||||||
@ -380,7 +381,14 @@ private
|
|||||||
end
|
end
|
||||||
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
|
def depends_on name, *args
|
||||||
@deps ||= []
|
@deps ||= []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user