require 'uri'
require 'pathname'
require 'chrysalis/repository'
require 'chrysalis/core_ext/string'
module Chrysalis
module VCS
module Subversion
# Implements support for checking out dependencies from a Subversion
# repository.
#
# Repositories of this type are identified by svn://,
# svn+ssh://, http://, or https:// URLs.
#
# Example:
# - http://svn.example.com/libfoo/trunk
# - http://code.example.com/svn/libfoo/trunk
# - svn://repository.local/libfoo/trunk
# - svn+ssh://ssh.example.com/libfoo/trunk
class Repository < Chrysalis::Repository
def self.retrieves?(url, params = {})
if params[:repository]
return (params[:repository] == 'svn' || params[:repository] == 'subversion')
end
uri = URI::parse(url)
return true if (uri.scheme == 'svn' || uri.scheme == 'svn+ssh')
return false if (uri.scheme != 'http' && uri.scheme != 'https')
return true if uri.host.begin? 'svn'
return true if uri.path.split('/').include? 'svn'
false
end
def initialize(url, params = {})
@url = url
@params = params
end
def retrieve(to = '.')
path = Pathname.new(to).join(checkout_to)
raise IOError, "Refusing to overwrite existing path. (path: #{path})" if path.exist?
unless @params[:noop]
puts ""
puts "Checking out #{@url} ..."
sh "svn co #{@url} #{path.cleanpath}"
end
WorkingCopy.new(:url => @url,
:path => path.cleanpath.to_s)
end
private
def checkout_to
return @params[:checkout_to] if @params[:checkout_to]
components = URI::parse(@url).path.split('/')
directory = components[-1]
raise ParameterError, "Invalid URL. (URL: #{@url})" if directory.nil?
if components[-1] == 'trunk'
directory = components[-2]
elsif components[-2] == 'branches' || components[-2] == 'tags'
directory = components[-3]
end
return directory
end
end
class WorkingCopy < Chrysalis::WorkingCopy
def self.type
:subversion
end
end
end
end
end