class Spaarti::Repo
Repo
object, handles individual repo syncing and state
Public Class Methods
new(data, client, params = {})
click to toggle source
# File lib/spaarti/repo.rb, line 7 def initialize(data, client, params = {}) @data = data @client = client @options = params @path = @options[:format] % @data end
Public Instance Methods
parent_of(repo)
click to toggle source
# File lib/spaarti/repo.rb, line 23 def parent_of(repo) repo.relative_path_from(Pathname.new(@path)).each_filename.first != '..' end
sync!()
click to toggle source
# File lib/spaarti/repo.rb, line 14 def sync! clone Dir.chdir(@path) do config add_upstream update_submodules end end
Private Instance Methods
add_upstream()
click to toggle source
# File lib/spaarti/repo.rb, line 61 def add_upstream return unless @data[:fork] return if `git remote`.split.include? 'upstream' upstream = @client.repo(@data[:id]).source.git_url run( "git remote add upstream '#{upstream}'", "Failed to add upstrema for #{@path}" ) end
clone()
click to toggle source
# File lib/spaarti/repo.rb, line 46 def clone return log("#{@data[:full_name]} already cloned") if Dir.exist? @path log "Cloning #{url} to #{@path}" run( "git clone '#{url}' '#{@path}'", "Failed to clone #{url}" ) end
config()
click to toggle source
# File lib/spaarti/repo.rb, line 55 def config @options[:git_config].each do |k, v| run("git config '#{k}' '#{v}'", "Failed to set config for #{@path}") end end
err(msg)
click to toggle source
# File lib/spaarti/repo.rb, line 33 def err(msg) warn msg end
log(msg)
click to toggle source
# File lib/spaarti/repo.rb, line 29 def log(msg) puts msg unless @options[:quiet] end
run(cmd, error_msg)
click to toggle source
# File lib/spaarti/repo.rb, line 37 def run(cmd, error_msg) res = system "#{cmd} 1>/dev/null 2>/dev/null" err(error_msg) unless res end
update_submodules()
click to toggle source
# File lib/spaarti/repo.rb, line 71 def update_submodules ['foreach git fetch --all --tags', 'update --init'].each do |cmd| run( "git submodule #{cmd}", "Failed to update submodules in #{@path}" ) end end
url()
click to toggle source
# File lib/spaarti/repo.rb, line 42 def url @url ||= @data["#{@options[:url_type]}_url".to_sym] end