summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan Jen <bryan.jen@gmail.com>2015-08-14 15:38:32 -0700
committerBryan Jen <bryan.jen@gmail.com>2015-08-14 15:38:32 -0700
commitd7534d7cfe98d62b8f0d9ae8adcc30bea483a1e2 (patch)
treecc617704a9e302b92976ea72d0d9b07b462917bc
parent5ef1b4740e1aab6672ee3971762c796c898ca639 (diff)
parent14c05f5d6c589bebc9f93eb117105c14ce7be6f1 (diff)
Merge pull request #261 from mhaskel/MODULES-2125
MODULES-2125 - Allow revision to be passed without source
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb18
-rw-r--r--spec/acceptance/create_repo_spec.rb16
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb10
3 files changed, 41 insertions, 3 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index f13802b..7617b13 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -76,7 +76,11 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
#updated and authoritative.
#TODO might be worthwhile to have an allow_local_changes param to decide
#whether to reset or pull when we're ensuring latest.
- at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") }
+ if @resource.value(:source)
+ at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") }
+ else
+ at_path { git_with_identity('reset', '--hard', "#{desired}") }
+ end
end
#TODO Would this ever reach here if it is bare?
if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true
@@ -392,7 +396,17 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
# @return [String] Returns the tag/branch of the current repo if it's up to
# date; otherwise returns the sha of the requested revision.
def get_revision(rev = 'HEAD')
- update_references
+ if @resource.value(:source)
+ update_references
+ else
+ status = at_path { git_with_identity('status')}
+ is_it_new = status =~ /Initial commit/
+ if is_it_new
+ status =~ /On branch (.*)/
+ branch = $1
+ return branch
+ end
+ end
current = at_path { git_with_identity('rev-parse', rev).strip }
if @resource.value(:revision)
if tag_revision?
diff --git a/spec/acceptance/create_repo_spec.rb b/spec/acceptance/create_repo_spec.rb
index db0cd29..53a93c9 100644
--- a/spec/acceptance/create_repo_spec.rb
+++ b/spec/acceptance/create_repo_spec.rb
@@ -30,6 +30,22 @@ describe 'create a repo' do
end
end
+ context 'no source but revision provided' do
+ it 'should not fail (MODULES-2125)' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/testrepo_blank_with_revision_repo":
+ ensure => present,
+ provider => git,
+ revision => 'master'
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ apply_manifest(pp, :catch_failures => true)
+ apply_manifest(pp, :catch_changes => true)
+ end
+ end
+
context 'bare repo' do
it 'creates a bare repo' do
pp = <<-EOS
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index a240b50..87113fa 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -206,7 +206,7 @@ branches
before do
expects_chdir('/tmp/test')
resource[:revision] = 'currentsha'
- resource.delete(:source)
+ resource[:source] = 'http://example.com'
provider.stubs(:git).with('config', 'remote.origin.url').returns('')
provider.stubs(:git).with('fetch', 'origin') # FIXME
provider.stubs(:git).with('fetch', '--tags', 'origin')
@@ -272,6 +272,14 @@ branches
end
end
+ context "when there's no source" do
+ it 'should return the revision' do
+ resource.delete(:source)
+ provider.expects(:git).with('status')
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
+ expect(provider.revision).to eq(resource.value(:revision))
+ end
+ end
end
context "setting the revision property" do