class TerraspaceBundler::Mod::Fetcher::Git

Public Instance Methods

clone() click to toggle source
# File lib/terraspace_bundler/mod/fetcher/git.rb, line 24
def clone
  command = ["git clone", ENV['TB_GIT_CLONE_ARGS'], @mod.url].compact.join(' ')
  sh command
rescue TB::GitError => e
  logger.error "ERROR: #{e.message}".color(:red)
  exit 1
end
copy_to_stage() click to toggle source
# File lib/terraspace_bundler/mod/fetcher/git.rb, line 60
def copy_to_stage
  cache_path = cache_path(rel_dest_dir)
  stage_path = stage_path(rel_dest_dir)
  FileUtils.rm_rf(stage_path)
  FileUtils.mkdir_p(File.dirname(stage_path))
  FileUtils.cp_r(cache_path, stage_path)
end
default_branch() click to toggle source

Note: if not in a git repo, will get this error message in stderr

fatal: Not a git repository (or any of the parent directories): .git
# File lib/terraspace_bundler/mod/fetcher/git.rb, line 42
def default_branch
  origin = `git remote show origin`.strip
  found = origin.split("\n").find { |l| l.include?("HEAD") }
  if found
    found.split(':').last.strip
  else
    'master'
  end
end
run() click to toggle source
# File lib/terraspace_bundler/mod/fetcher/git.rb, line 5
def run
  setup_tmp
  org_path = cache_path(@mod.org)
  FileUtils.mkdir_p(org_path)

  Dir.chdir(org_path) do
    logger.debug "Current root dir: #{org_path}"
    clone unless File.exist?(@mod.repo)

    Dir.chdir(@mod.repo) do
      logger.debug "Change dir: #{@mod.repo}"
      git "pull"
      git "submodule update --init"
      stage
    end
  end
end
stage() click to toggle source
# File lib/terraspace_bundler/mod/fetcher/git.rb, line 32
def stage
  copy_to_stage
  checkout = @mod.checkout_version || default_branch
  switch_version(checkout)
end
switch_version(version) click to toggle source
# File lib/terraspace_bundler/mod/fetcher/git.rb, line 52
def switch_version(version)
  stage_path = stage_path(rel_dest_dir)
  Dir.chdir(stage_path) do
    git "checkout #{version}"
    @sha = git("rev-parse HEAD").strip
  end
end