class CookbookOmnifetch::GitLocation

def install

Other tags:
    See: BaseLocation#install -
def install
  scratch_path = Pathname.new(Dir.mktmpdir)
  if cached?
    Dir.chdir(cache_path) do
      git %{fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"}
    end
  else
    git %{clone #{uri} "#{cache_path}" --bare --no-hardlinks}
  end
  Dir.chdir(cache_path) do
    @revision ||= git %{rev-parse #{@rev_parse}}
  end
  # Clone into a scratch directory for validations
  git %{clone --no-checkout "#{cache_path}" "#{scratch_path}"}
  # Make sure the scratch directory is up-to-date and account for rel paths
  Dir.chdir(scratch_path) do
    git %{fetch --force --tags "#{cache_path}"}
    git %{reset --hard #{@revision}}
    if rel
      git %{filter-branch --subdirectory-filter "#{rel}" --force}
    end
  end
  # Validate the scratched path is a valid cookbook
  validate_cached!(scratch_path)
  # If we got this far, we should copy
  FileUtils.rm_rf(install_path) if install_path.exist?
  FileUtils.cp_r(scratch_path, install_path)
  # Remove the git history
  FileUtils.rm_rf(File.join(install_path, ".git"))
  install_path.chmod(0777 & ~File.umask)
ensure
  # Ensure the scratch directory is cleaned up
  FileUtils.rm_rf(scratch_path) if scratch_path
end