summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb26
-rw-r--r--lib/puppet/type/vcsrepo.rb8
2 files changed, 29 insertions, 5 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index b2e893b..61044e0 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -79,12 +79,18 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
def revision=(desired)
checkout(desired)
- if local_branch_revision?(desired)
+ if local_branch_revision?
# reset instead of pull to avoid merge conflicts. assuming remote is
# authoritative.
# 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}") }
+ at_path {
+ git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}")
+ if detached?
+ git_with_identity('checkout', "#{@resource.value(:revision)}")
+ git_with_identity('pull')
+ end
+ }
end
if @resource.value(:ensure) != :bare
update_submodules
@@ -140,7 +146,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
if @resource.value(:remote) != 'origin'
args.push('--origin', @resource.value(:remote))
end
- if !File.exist?(File.join(@resource.value(:path), '.git'))
+ if !working_copy_exists?
args.push(source, path)
Dir.chdir("/") do
git_with_identity(*args)
@@ -259,7 +265,16 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end
def on_branch?
- at_path { git_with_identity('rev-parse', '--abbrev-ref', 'HEAD').chomp }
+ at_path {
+ matches = git_with_identity('branch', '-a').match /\*\s+(.*)/
+ matches[1] unless matches[1].match /detached/
+ }
+ end
+
+ def detached?
+ at_path {
+ git_with_identity('branch', '-a').match /\*\s+\(detached from.*\)/
+ }
end
def tags
@@ -271,6 +286,9 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end
def get_revision(rev)
+ if @resource.value(:force) && working_copy_exists?
+ create
+ end
if !working_copy_exists?
create
end
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb
index 1dab2b9..3dd7bc6 100644
--- a/lib/puppet/type/vcsrepo.rb
+++ b/lib/puppet/type/vcsrepo.rb
@@ -76,7 +76,7 @@ Puppet::Type.newtype(:vcsrepo) do
end
newvalue :latest, :required_features => [:reference_tracking] do
- if provider.exists?
+ if provider.exists? && !@resource.value(:force)
if provider.respond_to?(:update_references)
provider.update_references
end
@@ -97,6 +97,12 @@ Puppet::Type.newtype(:vcsrepo) do
prov = @resource.provider
if prov
if prov.working_copy_exists?
+ if @resource.value(:force)
+ notice "Deleting current repository before recloning"
+ prov.destroy
+ notice "Create repository from latest"
+ prov.create
+ end
(@should.include?(:latest) && prov.latest?) ? :latest : :present
elsif prov.class.feature?(:bare_repositories) and prov.bare_exists?
:bare