Class: OctocatalogDiff::CatalogUtil::Git
- Inherits:
-
Object
- Object
- OctocatalogDiff::CatalogUtil::Git
- Defined in:
- lib/octocatalog-diff/catalog-util/git.rb
Overview
Class to perform a git checkout (via ‘git archive’) of a branch from the base git directory into another targeted directory.
Class Method Summary collapse
-
.branch_sha(options = {}) ⇒ Object
Determine the SHA of origin/master (or any other branch really) in the git repo.
-
.check_out_git_archive(options = {}) ⇒ Object
Check out a branch via ‘git archive’ from one directory into another.
Class Method Details
.branch_sha(options = {}) ⇒ Object
Determine the SHA of origin/master (or any other branch really) in the git repo
61 62 63 64 65 66 67 68 69 |
# File 'lib/octocatalog-diff/catalog-util/git.rb', line 61 def self.branch_sha( = {}) branch = .fetch(:branch) dir = .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 |
.check_out_git_archive(options = {}) ⇒ Object
Check out a branch via ‘git archive’ from one directory into another.
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 |
# File 'lib/octocatalog-diff/catalog-util/git.rb', line 19 def self.check_out_git_archive( = {}) branch = .fetch(:branch) path = .fetch(:path) dir = .fetch(:basedir) logger = .fetch(:logger) override_script_path = .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 => [: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 |