Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

Commit

Permalink
Support using commits for GClone spec searcher
Browse files Browse the repository at this point in the history
This fixes a bug with the `GClone` spec searcher that caused `git clone`
to fail when provided a commit to clone. Because `git clone` does
not support cloning a specific commit (using a SHA1), it's necessary to
clone the entire repository. This updates the `git clone` command used
by the spec searcher accordingly.
  • Loading branch information
beechtom committed Jun 27, 2022
1 parent 9959d47 commit f40c454
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/puppetfile-resolver/spec_searchers/git/gclone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,24 @@ def self.metadata(puppetfile_module, resolver_ui, config)
# @param file [String] the file you wish to read
# @returns [String] the content of the file
def self.clone_and_read_file(url, ref, file, config)
clone_cmd = ['git', 'clone', '--bare', '--depth=1', '--single-branch']
err_msg = ''
if config.proxy
err_msg += " with proxy #{config.proxy}: "
proxy = "--config \"http.proxy=#{config.proxy}\" --config \"https.proxy=#{config.proxy}\""
clone_cmd.push(proxy)
end

Dir.mktmpdir(nil, config.clone_dir) do |dir|
clone_cmd.push("--branch=#{ref}") if ref != 'HEAD'
clone_cmd.push(url, dir)
clone_cmd = ['git', 'clone', url, dir]

if config.proxy
clone_cmd += ['--config', "http.proxy=#{config.proxy}", '--config', "https.proxy=#{config.proxy}"]
end

out, err_out, process = ::PuppetfileResolver::Util.run_command(clone_cmd)
err_msg += err_out
raise err_msg unless process.success?

unless process.success?
msg = if config.proxy
"Cloning #{url} with proxy #{config.proxy} failed: #{err_out}"
else
"Cloning #{url} failed: #{err_out}"
end
raise msg
end

Dir.chdir(dir) do
content, err_out, process = ::PuppetfileResolver::Util.run_command(['git', 'show', "#{ref}:#{file}"])
raise 'InvalidContent' unless process.success? && content.length > 2
Expand Down

0 comments on commit f40c454

Please sign in to comment.