class Blaggard::Git

Attributes

git_path[RW]
repo[RW]

Public Class Methods

new(repo, path = nil) click to toggle source
# File lib/blaggard/git.rb, line 6
def initialize(repo, path = nil)
  @repo = repo
  @git_path = path ? path : 'git'
end

Public Instance Methods

capture(command) click to toggle source
# File lib/blaggard/git.rb, line 38
def capture(command)
  IO.popen(popen_env, command, popen_options).read
end
command(cmd) click to toggle source
# File lib/blaggard/git.rb, line 34
def command(cmd)
  [git_path || 'git'] + cmd.flatten
end
execute(cmd) { |pipe| ... } click to toggle source
# File lib/blaggard/git.rb, line 11
def execute(cmd)
  cmd = command(cmd)
  if block_given?
    IO.popen(popen_env, cmd, File::RDWR, popen_options) do |pipe|
      yield(pipe)
    end
  else
    capture(cmd).chomp
  end
end
get_config_setting(service_name) click to toggle source
# File lib/blaggard/git.rb, line 50
def get_config_setting(service_name)
  service_name = service_name.gsub('-', '')
  setting = get_git_config("http.#{service_name}")
  if service_name == 'uploadpack'
    return setting != 'false'
  else
    return setting == 'true'
  end
end
get_git_config(config_name) click to toggle source
# File lib/blaggard/git.rb, line 60
def get_git_config(config_name)
  execute(%W(config #{config_name}))
end
popen_env() click to toggle source
# File lib/blaggard/git.rb, line 46
def popen_env
  {'PATH' => ENV['PATH'], 'GL_ID' => ENV['GL_ID']}
end
popen_options() click to toggle source
# File lib/blaggard/git.rb, line 42
def popen_options
  {chdir: repo, unsetenv_others: true}
end
tags_on_branch(commitish) click to toggle source
# File lib/blaggard/git.rb, line 27
def tags_on_branch(commitish)
  opts = %W(--simplify-by-decoration --decorate --pretty=oneline)
  return execute(['log', opts, commitish]).scan(/tag: (.*?)(\,|\))/).map{ |match| match.first}
rescue => e
  []
end
time_ordered_refs() click to toggle source
# File lib/blaggard/git.rb, line 22
def time_ordered_refs
  opts = %W(--sort=-committerdate refs/heads/ --format=%(refname))
  return execute(['for-each-ref', opts]).split("\n")
end
update_server_info() click to toggle source
# File lib/blaggard/git.rb, line 77
def update_server_info
  # TODO: Update this for use with ACL
  execute(%W(update-server-info))
end
valid_repo?() click to toggle source
# File lib/blaggard/git.rb, line 64
def valid_repo?
  return false unless File.exists?(repo) &&
    File.realpath(repo) == repo
  match = execute(%W(rev-parse --git-dir)).match(/\.$|\.git$/)

  if match.to_s == '.git'
    # Since the parent could be a git repo, we want to make sure the actual repo contains a git dir.
    return false unless Dir.entries(repo).include?('.git')
  end

  !!match
end