/usr/lib/ruby/vendor_ruby/octocatalog-diff/catalog-util/git.rb is in octocatalog-diff 1.5.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | # frozen_string_literal: true
require 'rugged'
require_relative '../errors'
require_relative '../util/scriptrunner'
module OctocatalogDiff
module CatalogUtil
# Class to perform a git checkout (via 'git archive') of a branch from the base git
# directory into another targeted directory.
class Git
# Check out a branch via 'git archive' from one directory into another.
# @param options [Hash] Options hash:
# - :branch => Branch name to check out
# - :path => Where to check out to (must exist as a directory)
# - :basedir => Where to check out from (must exist as a directory)
# - :logger => Logger object
def self.check_out_git_archive(options = {})
branch = options.fetch(:branch)
path = options.fetch(:path)
dir = options.fetch(:basedir)
logger = options.fetch(:logger)
override_script_path = options.fetch(:override_script_path, nil)
# Validate parameters
if dir.nil? || !File.directory?(dir)
raise OctocatalogDiff::Errors::GitCheckoutError, "Source directory #{dir.inspect} does not exist"
end
if path.nil? || !File.directory?(path)
raise OctocatalogDiff::Errors::GitCheckoutError, "Target directory #{path.inspect} does not exist"
end
# Create and execute checkout script
sr_opts = {
logger: logger,
default_script: 'git-extract/git-extract.sh',
override_script_path: override_script_path
}
script = OctocatalogDiff::Util::ScriptRunner.new(sr_opts)
sr_run_opts = {
:working_dir => dir,
:pass_env_vars => options[:pass_env_vars],
'OCD_GIT_EXTRACT_BRANCH' => branch,
'OCD_GIT_EXTRACT_TARGET' => path
}
begin
script.run(sr_run_opts)
logger.debug("Success git archive #{dir}:#{branch}")
rescue OctocatalogDiff::Util::ScriptRunner::ScriptException
raise OctocatalogDiff::Errors::GitCheckoutError, "Git archive #{branch}->#{path} failed: #{script.output}"
end
end
# Determine the SHA of origin/master (or any other branch really) in the git repo
# @param options [Hash] Options hash:
# - :branch => Branch name to determine SHA of
# - :basedir => Where to check out from (must exist as a directory)
def self.branch_sha(options = {})
branch = options.fetch(:branch)
dir = options.fetch(:basedir)
if dir.nil? || !File.directory?(dir)
raise Errno::ENOENT, "Git directory #{dir.inspect} does not exist"
end
repo = Rugged::Repository.new(dir)
repo.branches[branch].target_id
end
end
end
end
|