class Gouteur::Repo

a repository of code that depends on the library under test

Attributes

name[R]
ref[R]
tasks[R]
to_s[R]
uri[R]

Public Class Methods

new(uri:, ref: nil, before: [], tasks: 'rake', locked: false) click to toggle source
# File lib/gouteur/repo.rb, line 9
def initialize(uri:, ref: nil, before: [], tasks: 'rake', locked: false)
  @uri    = URI.parse(uri)
  @name   = extract_name_from_uri(uri)
  @ref    = ref
  @before = Array(before)
  @tasks  = Array(tasks)
  @locked = !!locked
end

Public Instance Methods

bundle() click to toggle source
# File lib/gouteur/repo.rb, line 34
def bundle
  @bundle ||= Gouteur::Bundle.new(clone_path)
end
clone_path() click to toggle source
# File lib/gouteur/repo.rb, line 30
def clone_path
  File.join(store_dir, name)
end
fetch() click to toggle source
# File lib/gouteur/repo.rb, line 18
def fetch
  cloned? ? pull : clone
end
locked?() click to toggle source
# File lib/gouteur/repo.rb, line 38
def locked?
  @locked
end
prepare() click to toggle source
# File lib/gouteur/repo.rb, line 22
def prepare
  @before.each { |cmd| Shell.run!(cmd, pwd: clone_path) }
end
remove() click to toggle source
# File lib/gouteur/repo.rb, line 26
def remove
  cloned? && Shell.run!(%W[rm -rf #{clone_path}])
end

Private Instance Methods

clone() click to toggle source
# File lib/gouteur/repo.rb, line 61
def clone
  Shell.run!(%W[mkdir -p #{store_dir}])
  Shell.run!(%W[git clone --quiet #{uri} #{clone_path}])
  Shell.run!(%W[git checkout #{ref}], pwd: clone_path) if ref
end
cloned?() click to toggle source
# File lib/gouteur/repo.rb, line 50
def cloned?
  File.exist?(clone_path)
end
extract_name_from_uri(uri) click to toggle source
# File lib/gouteur/repo.rb, line 44
def extract_name_from_uri(uri)
  uri[%r{git(?:hub|lab)\.com/[^/]+/([^/]+)}, 1] ||
    uri.split('/').last.to_s[/[a-z0-9\-_]+/i] ||
    raise(Error, 'could not determine repository name from uri')
end
pull() click to toggle source
# File lib/gouteur/repo.rb, line 54
def pull
  Shell.run!(%w[git fetch origin], pwd: clone_path)
  Shell.run!(%w[git reset --hard --quiet], pwd: clone_path)
  Shell.run!(%w[git clean -f -d -x], pwd: clone_path)
  Shell.run!(%w[git pull --ff-only --quiet], pwd: clone_path)
end
store_dir() click to toggle source
# File lib/gouteur/repo.rb, line 67
def store_dir
  File.join(Host.root, 'tmp', 'gouteur_repos')
end