GitDownloadStrategy: split #fetch into several methods
This commit is contained in:
parent
37b28741f2
commit
e186d9a136
@ -311,55 +311,23 @@ class GitDownloadStrategy < AbstractDownloadStrategy
|
|||||||
@clone
|
@clone
|
||||||
end
|
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
|
def fetch
|
||||||
raise "You must: brew install git" unless which "git"
|
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
|
Dir.chdir(@clone) do
|
||||||
# Check for interupted clone from a previous install
|
config_repo
|
||||||
unless quiet_system @@git, 'status', '-s'
|
fetch_repo
|
||||||
|
end
|
||||||
|
elsif @clone.exist?
|
||||||
puts "Removing invalid .git repo from cache"
|
puts "Removing invalid .git repo from cache"
|
||||||
FileUtils.rm_rf @clone
|
FileUtils.rm_rf @clone
|
||||||
end
|
clone_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)
|
|
||||||
else
|
else
|
||||||
puts "Updating #{@clone}"
|
clone_repo
|
||||||
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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -367,7 +335,7 @@ class GitDownloadStrategy < AbstractDownloadStrategy
|
|||||||
dst = Dir.getwd
|
dst = Dir.getwd
|
||||||
Dir.chdir @clone do
|
Dir.chdir @clone do
|
||||||
if @spec and @ref
|
if @spec and @ref
|
||||||
ohai "Checking out #{@spec} #{@ref}"
|
ohai "Checking out #@spec #@ref"
|
||||||
case @spec
|
case @spec
|
||||||
when :branch
|
when :branch
|
||||||
nostdout { quiet_safe_system @@git, 'checkout', { :quiet_flag => '-q' }, "origin/#{@ref}", '--' }
|
nostdout { quiet_safe_system @@git, 'checkout', { :quiet_flag => '-q' }, "origin/#{@ref}", '--' }
|
||||||
@ -391,6 +359,52 @@ class GitDownloadStrategy < AbstractDownloadStrategy
|
|||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class CVSDownloadStrategy < AbstractDownloadStrategy
|
class CVSDownloadStrategy < AbstractDownloadStrategy
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user