Skip to content

Commit 5a55794

Browse files
committed
Support using commits for GClone spec searcher
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.
1 parent 9959d47 commit 5a55794

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

lib/puppetfile-resolver/spec_searchers/git/gclone.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,21 @@ def self.metadata(puppetfile_module, resolver_ui, config)
4545
# @param file [String] the file you wish to read
4646
# @returns [String] the content of the file
4747
def self.clone_and_read_file(url, ref, file, config)
48-
clone_cmd = ['git', 'clone', '--bare', '--depth=1', '--single-branch']
49-
err_msg = ''
50-
if config.proxy
51-
err_msg += " with proxy #{config.proxy}: "
52-
proxy = "--config \"http.proxy=#{config.proxy}\" --config \"https.proxy=#{config.proxy}\""
53-
clone_cmd.push(proxy)
54-
end
55-
5648
Dir.mktmpdir(nil, config.clone_dir) do |dir|
57-
clone_cmd.push("--branch=#{ref}") if ref != 'HEAD'
58-
clone_cmd.push(url, dir)
59-
out, err_out, process = ::PuppetfileResolver::Util.run_command(clone_cmd)
60-
err_msg += err_out
61-
raise err_msg unless process.success?
49+
clone_cmd = ['git', 'clone', url, dir]
50+
clone_cmd += ['--config', "http.proxy=#{config.proxy}", '--config', "https.proxy=#{config.proxy}"] if config.proxy
51+
52+
_out, err_out, process = ::PuppetfileResolver::Util.run_command(clone_cmd)
53+
54+
unless process.success?
55+
msg = if config.proxy
56+
"Cloning #{url} with proxy #{config.proxy} failed: #{err_out}"
57+
else
58+
"Cloning #{url} failed: #{err_out}"
59+
end
60+
raise msg
61+
end
62+
6263
Dir.chdir(dir) do
6364
content, err_out, process = ::PuppetfileResolver::Util.run_command(['git', 'show', "#{ref}:#{file}"])
6465
raise 'InvalidContent' unless process.success? && content.length > 2

spec/unit/puppetfile-resolver/spec_searchers/git/gclone_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
expect(JSON.parse(content)['name']).to eq('puppetlabs-powershell')
2424
end
2525

26-
context 'with ref' do
27-
26+
context 'with tag' do
2827
let(:puppetfile_module) do
2928
PuppetfileModule.new(remote: url, ref: '2.1.2')
3029
end
@@ -34,6 +33,17 @@
3433
expect(JSON.parse(content)['name']).to eq('puppetlabs-powershell')
3534
end
3635
end
36+
37+
context 'with commit' do
38+
let(:puppetfile_module) do
39+
PuppetfileModule.new(remote: url, ref: '9276de695798097e8471b877a18df27f764eecda')
40+
end
41+
42+
it 'reads metadata' do
43+
content = subject.metadata(puppetfile_module, Logger.new(STDERR), config)
44+
expect(JSON.parse(content)['name']).to eq('puppetlabs-powershell')
45+
end
46+
end
3747
end
3848

3949
context 'invalid url' do

0 commit comments

Comments
 (0)