class Dotstrap::Git
TODO: split this into Git
< Downloader class
Attributes
repo[RW]
repo_name[RW]
repo_owner[RW]
repo_path[RW]
url[RW]
Public Class Methods
new(repo, dest_dir = Dotstrap.config_home)
click to toggle source
# File lib/dotstrap/git.rb, line 9 def initialize(repo, dest_dir = Dotstrap.config_home) @repo = determine_repo_slug(repo) # TODO: allow an option to specify to download with SSH or HTTPs from Git @url = determine_url(@repo) @repo_owner, @repo_name = split_repo_slug(@repo) # @repo_path = File.join(dest_dir, "#{@repo_owner}.#{@repo_name}") @repo_path = File.join(dest_dir, "#{@repo_owner}-#{@repo_name}") # @repo_path = File.join(dest_dir, @github_user, @repo_name) end
Public Instance Methods
clone(url = @url, repo_path = @repo_path, repo = @repo)
click to toggle source
FIXME: if user is not logged in to Git
the prompt for username/password is mangled because the threads are not synchronized
# File lib/dotstrap/git.rb, line 21 def clone(url = @url, repo_path = @repo_path, repo = @repo) return pull(repo_path) if Dir.exist?(repo_path) return false unless system('git', 'clone', *git_verbosity, url, repo_path) $LOG.debug { "CLONE #{repo} #{url} #{repo_path}" } $LOG.unknown { "#{'=> '.colorize(:blue)}#{repo}\nupdated" } repo_path end
pull(repo_path = @repo_path, repo = @repo)
click to toggle source
# File lib/dotstrap/git.rb, line 29 def pull(repo_path = @repo_path, repo = @repo) Dir.chdir(repo_path) return false unless system('git', 'pull', *git_verbosity, repo_path) $LOG.debug { "PULL #{repo} #{url} #{repo_path}" } $LOG.unknown { "#{'=> '.colorize(:blue)}#{repo}\nupdated" } repo_path end
Private Instance Methods
determine_repo_slug(repo)
click to toggle source
# File lib/dotstrap/git.rb, line 39 def determine_repo_slug(repo) return repo unless repo.start_with?("http", "git@") repo = repo.gsub(/(https?:\/\/github.com\/)|(git@github.com:)/,"") repo = repo.gsub(/.git/,"") end
determine_url(repo)
click to toggle source
# File lib/dotstrap/git.rb, line 45 def determine_url(repo) return repo if repo.start_with?("http", "git@") "https://github.com/#{repo}" end
git_verbosity()
click to toggle source
# File lib/dotstrap/git.rb, line 57 def git_verbosity if $LOG.debug? '--verbose' else return '--quiet' end end
split_repo_slug(repo, sep = "/")
click to toggle source
# File lib/dotstrap/git.rb, line 50 def split_repo_slug(repo, sep = "/") partition = repo.partition(sep) # TODO: make dotstrap ansible role compatible # return partition[0], partition[2].gsub("ansible-", "") return partition[0], partition[2].gsub("ansible-", "") end