|
4 | 4 | require 'open3' |
5 | 5 | require 'rugged' |
6 | 6 | require 'shellwords' |
7 | | -require 'tempfile' |
8 | 7 |
|
9 | 8 | require_relative '../errors' |
| 9 | +require_relative '../util/scriptrunner' |
10 | 10 |
|
11 | 11 | module OctocatalogDiff |
12 | 12 | module CatalogUtil |
@@ -34,31 +34,23 @@ def self.check_out_git_archive(options = {}) |
34 | 34 | end |
35 | 35 |
|
36 | 36 | # Create and execute checkout script |
37 | | - script = create_git_checkout_script(branch, path) |
38 | | - logger.debug("Begin git archive #{dir}:#{branch} -> #{path}") |
39 | | - output, status = Open3.capture2e(script, chdir: dir) |
40 | | - unless status.exitstatus.zero? |
41 | | - raise OctocatalogDiff::Errors::GitCheckoutError, "Git archive #{branch}->#{path} failed: #{output}" |
42 | | - end |
43 | | - logger.debug("Success git archive #{dir}:#{branch}") |
44 | | - end |
| 37 | + sr_opts = { |
| 38 | + logger: logger, |
| 39 | + default_script: 'git-extract/git-extract.sh' |
| 40 | + } |
| 41 | + script = OctocatalogDiff::Util::ScriptRunner.new(sr_opts) |
45 | 42 |
|
46 | | - # Create the temporary file used to interact with the git command line. |
47 | | - # To get the options working correctly (-o pipefail in particular) this needs to run under |
48 | | - # bash. It's just creating a script, rather than figuring out all the shell escapes... |
49 | | - # @param branch [String] Branch name |
50 | | - # @param path [String] Target directory |
51 | | - # @return [String] Name of script |
52 | | - def self.create_git_checkout_script(branch, path) |
53 | | - tmp_script = Tempfile.new(['git-checkout', '.sh']) |
54 | | - tmp_script.write "#!/bin/bash\n" |
55 | | - tmp_script.write "set -euf -o pipefail\n" |
56 | | - tmp_script.write "git archive --format=tar #{Shellwords.escape(branch)} | \\\n" |
57 | | - tmp_script.write " ( cd #{Shellwords.escape(path)} && tar -xf - )\n" |
58 | | - tmp_script.close |
59 | | - FileUtils.chmod 0o755, tmp_script.path |
60 | | - at_exit { FileUtils.rm_f tmp_script.path if File.exist?(tmp_script.path) } |
61 | | - tmp_script.path |
| 43 | + sr_run_opts = { |
| 44 | + :working_dir => dir, |
| 45 | + 'OCD_GIT_EXTRACT_BRANCH' => branch, |
| 46 | + 'OCD_GIT_EXTRACT_TARGET' => path |
| 47 | + } |
| 48 | + begin |
| 49 | + script.run(sr_run_opts) |
| 50 | + logger.debug("Success git archive #{dir}:#{branch}") |
| 51 | + rescue OctocatalogDiff::Util::ScriptRunner::ScriptException |
| 52 | + raise OctocatalogDiff::Errors::GitCheckoutError, "Git archive #{branch}->#{path} failed: #{script.output}" |
| 53 | + end |
62 | 54 | end |
63 | 55 |
|
64 | 56 | # Determine the SHA of origin/master (or any other branch really) in the git repo |
|
0 commit comments