Skip to content

Commit

Permalink
(maint) Fixes a bug when a custom template-url is provided to convert…
Browse files Browse the repository at this point in the history
… and default ref is a tag
  • Loading branch information
bmjen committed Feb 22, 2018
1 parent ddd7ed1 commit f28b18e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/pdk/module/templatedir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def initialize(path_or_url, module_metadata = {}, init = false)
# template repo in `%AppData%` or `$XDG_CACHE_DIR` and update before
# use.
temp_dir = PDK::Util.make_tmpdir_name('pdk-templates')
git_ref = PDK::Util.default_template_ref
git_ref = (path_or_url == PDK::Util.default_template_url) ? PDK::Util.default_template_ref : 'origin/master'

clone_result = PDK::Util::Git.git('clone', path_or_url, temp_dir)

Expand Down
23 changes: 23 additions & 0 deletions spec/unit/pdk/module/template_dir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
before(:each) do
allow(File).to receive(:directory?).with(anything).and_return(true)
allow(File).to receive(:directory?).with(path_or_url).and_return(false)
allow(PDK::Util).to receive(:default_template_url).and_return(path_or_url)
allow(PDK::Util).to receive(:default_template_ref).and_return('default-ref')
allow(PDK::Util).to receive(:make_tmpdir_name).with('pdk-templates').and_return(tmp_path)
allow(PDK::Util::Git).to receive(:git).with('clone', path_or_url, tmp_path).and_return(exit_code: 0)
Expand All @@ -249,4 +250,26 @@
end
end
end

describe 'custom template' do
before(:each) do
allow(File).to receive(:directory?).with(anything).and_return(true)
allow(File).to receive(:directory?).with(path_or_url).and_return(false)
allow(PDK::Util).to receive(:default_template_url).and_return('default-url')
allow(PDK::Util).to receive(:default_template_ref).and_return('default-ref')
allow(PDK::Util).to receive(:make_tmpdir_name).with('pdk-templates').and_return(tmp_path)
allow(PDK::Util::Git).to receive(:git).with('clone', path_or_url, tmp_path).and_return(exit_code: 0)
allow(PDK::Util::Git).to receive(:git).with('-C', tmp_path, 'reset', '--hard', 'origin/master').and_return(exit_code: 0)
allow(FileUtils).to receive(:remove_dir).with(tmp_path)
allow(PDK::Util::Git).to receive(:git).with('--git-dir', anything, 'describe', '--all', '--long', '--always').and_return(exit_code: 0, stdout: '1234abcd')
allow(PDK::Util::Version).to receive(:version_string).and_return('0.0.0')
allow(PDK::Util).to receive(:canonical_path).with(tmp_path).and_return(tmp_path)
end

context 'pdk data' do
it 'includes the PDK version and template info' do
expect(template_dir.metadata).to include('pdk-version' => '0.0.0', 'template-url' => path_or_url, 'template-ref' => '1234abcd')
end
end
end
end

0 comments on commit f28b18e

Please sign in to comment.