module GitDeploy::Configuration

Private Instance Methods

branch() click to toggle source
# File lib/git_deploy/configuration.rb, line 30
def branch
  'master'
end
current_branch() click to toggle source
# File lib/git_deploy/configuration.rb, line 71
def current_branch
  git_config['symbolic-ref -q HEAD']
end
deploy_to() click to toggle source
# File lib/git_deploy/configuration.rb, line 13
def deploy_to
  @deploy_to ||= begin
    if remote_url.path.start_with? '/~/'
      remote_url.path[1..-1]
    else
      remote_url.path 
    end
  end
end
git_config() click to toggle source
# File lib/git_deploy/configuration.rb, line 34
def git_config
  @git_config ||= Hash.new do |cache, cmd|
    git = ENV['GIT'] || 'git'
    out = `#{git} #{cmd}`
    if $?.success? then cache[cmd] = out.chomp
    else cache[cmd] = nil
    end
    cache[cmd]
  end
end
normalize_branch(branch) click to toggle source
# File lib/git_deploy/configuration.rb, line 80
def normalize_branch(branch)
  branch.sub('refs/heads/', '')
end
remote_for(branch) click to toggle source
# File lib/git_deploy/configuration.rb, line 84
def remote_for(branch)
  git_config['config branch.%s.remote' % normalize_branch(branch)]
end
remote_url(remote = options[:remote]) click to toggle source
# File lib/git_deploy/configuration.rb, line 51
def remote_url(remote = options[:remote])
  @remote_url ||= {}
  @remote_url[remote] ||= begin
    url = remote_urls(remote).first
    if url.nil?
      abort "Error: Remote url not found for remote #{remote.inspect}"
    elsif url =~ /(^|@)github\.com\b/
      abort "Error: Remote url for #{remote.inspect} points to GitHub. Can't deploy there!"
    else
      url = 'ssh://' + url.sub(%r{:/?}, '/') unless url =~ %r{^[\w-]+://}
      begin
        url = URI.parse url
      rescue
        abort "Error parsing remote url #{url}"
      end
    end
    url
  end
end
remote_urls(remote) click to toggle source
# File lib/git_deploy/configuration.rb, line 45
def remote_urls(remote)
  git_config["remote -v"].to_s.split("\n").
    select {|l| l =~ /^#{remote}\t.+/ }.
    map {|l| l.split("\t")[1].sub(/\s+\(.+?\)$/, '') }
end
remote_user() click to toggle source
# File lib/git_deploy/configuration.rb, line 23
def remote_user
  @user ||= begin
    user = remote_url.user
    user ? CGI.unescape(user) : `whoami`.chomp
  end
end
tracked_branch() click to toggle source
# File lib/git_deploy/configuration.rb, line 75
def tracked_branch
  branch = current_branch && tracked_for(current_branch)
  normalize_branch(branch) if branch
end
tracked_for(branch) click to toggle source
# File lib/git_deploy/configuration.rb, line 88
def tracked_for(branch)
  git_config['config branch.%s.merge' % normalize_branch(branch)]
end