aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJannis Leidel2009-10-17 14:35:24 +0200
committerMax Howell2009-10-19 04:02:48 +0100
commit96d166ef01cdedf375bc83e63e57871ff49d8912 (patch)
tree4e3c559968a493036be51007d63e78ccff54d80a /Library
parent0d076d2ca6535568bf979979c7e6a4bc7fc1b1dc (diff)
downloadhomebrew-96d166ef01cdedf375bc83e63e57871ff49d8912.tar.bz2
Fix #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'
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/download_strategy.rb29
-rw-r--r--Library/Homebrew/formula.rb14
2 files changed, 37 insertions, 6 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 3b9a9dd49..fc5cdfef0 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -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
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 6fa22feae..5d022d098 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -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 ||= []