class Argus::Git

Attributes

branch[R]
org[R]
repo[R]
sha[R]

Public Class Methods

new(org, repo, branch = 'master', sha = nil) click to toggle source
# File lib/argus/git.rb, line 5
def initialize(org, repo, branch = 'master', sha = nil)
  @org    = org
  @repo   = repo
  @branch = branch
  @sha    = sha
end

Public Instance Methods

checkout() click to toggle source

checkout branch of an existing repo

# File lib/argus/git.rb, line 42
def checkout
  puts "repo exists, pulling #{self}"
  %x[git fetch && git checkout -f #{branch} && git reset --hard origin/#{branch}]
  raise ArgusError, "git checkout failed for #{self}" unless $? == 0
end
clone() click to toggle source

clone a new repo

# File lib/argus/git.rb, line 49
def clone
  puts "new repo, cloning #{self}"
  %x[git clone -b #{branch} #{url} .] # not found: clone it
  raise ArgusError, "git clone failed for #{self}" unless $? == 0
end
is_inside_work_tree?() click to toggle source

is this dir a git repo?

# File lib/argus/git.rb, line 26
def is_inside_work_tree?
  %x[git rev-parse --is-inside-work-tree 2> /dev/null].chomp == 'true'
end
pull() click to toggle source

pull existing, or new git repo, and return sha

# File lib/argus/git.rb, line 31
def pull
  if is_inside_work_tree?
    checkout
  else
    clone
  end
  reset if sha              # specific sha was requested
  @sha = rev_parse          # return sha
end
reset() click to toggle source

get a specific commit

# File lib/argus/git.rb, line 56
def reset
  puts "specific sha requested, resetting to #{sha}"
  %x[git fetch && git reset --hard #{sha}]
end
rev_parse() click to toggle source

get current sha

# File lib/argus/git.rb, line 62
def rev_parse
  %x[git rev-parse #{branch} ].chomp
end
to_s() click to toggle source
# File lib/argus/git.rb, line 12
def to_s
  "#{org}/#{repo}:#{branch}"
end
url() click to toggle source

if we have a token, use https, else depend on ssh being set up

# File lib/argus/git.rb, line 17
def url
  if ENV['GITHUB_TOKEN']
    "https://#{ENV['GITHUB_TOKEN']}@github.com/#{org}/#{repo}.git"
  else
    "git@github.com:#{org}/#{repo}.git"
  end
end