aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJack Nagel2013-02-14 17:29:58 -0600
committerJack Nagel2013-02-14 17:29:58 -0600
commite186d9a13637cb8bfe32e92c35c549a58c44079d (patch)
tree181c4ac9a7cc82039b6ae237ecb81b4efcc431f7 /Library
parent37b28741f2903e568d166ff2e2207dff93f83c43 (diff)
downloadbrew-e186d9a13637cb8bfe32e92c35c549a58c44079d.tar.bz2
GitDownloadStrategy: split #fetch into several methods
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/download_strategy.rb100
1 files changed, 57 insertions, 43 deletions
diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb
index 37fb3cfc6..c3d3e04e2 100644
--- a/Library/Homebrew/download_strategy.rb
+++ b/Library/Homebrew/download_strategy.rb
@@ -311,55 +311,23 @@ class GitDownloadStrategy < AbstractDownloadStrategy
@clone
end
- def support_depth?
- @spec != :revision and host_supports_depth?
- end
-
- def host_supports_depth?
- @url =~ %r(git://) or @url =~ %r(https://github.com/)
- end
-
def fetch
raise "You must: brew install git" unless which "git"
- ohai "Cloning #{@url}"
+ ohai "Cloning #@url"
- if @clone.exist?
+ if @clone.exist? && repo_valid?
+ puts "Updating #@clone"
Dir.chdir(@clone) do
- # Check for interupted clone from a previous install
- unless quiet_system @@git, 'status', '-s'
- puts "Removing invalid .git repo from cache"
- FileUtils.rm_rf @clone
- end
+ config_repo
+ fetch_repo
end
- end
-
- unless @clone.exist?
- # Note: first-time checkouts are always done verbosely
- clone_args = [@@git, 'clone', '--no-checkout']
- clone_args << '--depth' << '1' if support_depth?
-
- case @spec
- when :branch, :tag
- clone_args << '--branch' << @ref
- end
-
- clone_args << @url << @clone
- safe_system(*clone_args)
+ elsif @clone.exist?
+ puts "Removing invalid .git repo from cache"
+ FileUtils.rm_rf @clone
+ clone_repo
else
- puts "Updating #{@clone}"
- Dir.chdir(@clone) do
- safe_system @@git, 'config', 'remote.origin.url', @url
-
- safe_system @@git, 'config', 'remote.origin.fetch', case @spec
- when :branch then "+refs/heads/#{@ref}:refs/remotes/origin/#{@ref}"
- when :tag then "+refs/tags/#{@ref}:refs/tags/#{@ref}"
- else '+refs/heads/master:refs/remotes/origin/master'
- end
-
- git_args = [@@git, 'fetch', 'origin']
- quiet_safe_system(*git_args)
- end
+ clone_repo
end
end
@@ -367,7 +335,7 @@ class GitDownloadStrategy < AbstractDownloadStrategy
dst = Dir.getwd
Dir.chdir @clone do
if @spec and @ref
- ohai "Checking out #{@spec} #{@ref}"
+ ohai "Checking out #@spec #@ref"
case @spec
when :branch
nostdout { quiet_safe_system @@git, 'checkout', { :quiet_flag => '-q' }, "origin/#{@ref}", '--' }
@@ -391,6 +359,52 @@ class GitDownloadStrategy < AbstractDownloadStrategy
end
end
end
+
+ private
+
+ def support_depth?
+ @spec != :revision and host_supports_depth?
+ end
+
+ def host_supports_depth?
+ @url =~ %r{git://} or @url =~ %r{https://github.com/}
+ end
+
+ def repo_valid?
+ quiet_system @@git, "--git-dir", "#@clone/.git", "status", "-s"
+ end
+
+ def clone_args
+ args = %w{clone --no-checkout}
+ args << '--depth' << '1' if support_depth?
+
+ case @spec
+ when :branch, :tag then args << '--branch' << @ref
+ end
+
+ args << @url << @clone
+ end
+
+ def refspec
+ case @spec
+ when :branch then "+refs/heads/#@ref:refs/remotes/origin/#@ref"
+ when :tag then "+refs/tags/#@ref:refs/tags/#@ref"
+ else "+refs/heads/master:refs/remotes/origin/master"
+ end
+ end
+
+ def config_repo
+ safe_system @@git, 'config', 'remote.origin.url', @url
+ safe_system @@git, 'config', 'remote.origin.fetch', refspec
+ end
+
+ def fetch_repo
+ quiet_safe_system @@git, 'fetch', 'origin'
+ end
+
+ def clone_repo
+ safe_system @@git, *clone_args
+ end
end
class CVSDownloadStrategy < AbstractDownloadStrategy