summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMorgan Haskel <morgan@puppetlabs.com>2015-08-13 16:02:22 -0700
committerMorgan Haskel <morgan@puppetlabs.com>2015-08-14 15:32:10 -0700
commit14c05f5d6c589bebc9f93eb117105c14ce7be6f1 (patch)
treecc617704a9e302b92976ea72d0d9b07b462917bc /lib
parent5ef1b4740e1aab6672ee3971762c796c898ca639 (diff)
MODULES-2125 - Allow revision to be passed without source
Will also work with empty repositories.
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb18
1 files changed, 16 insertions, 2 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?