summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb80
-rw-r--r--lib/puppet/provider/vcsrepo/svn.rb7
-rw-r--r--lib/puppet/type/vcsrepo.rb14
3 files changed, 89 insertions, 12 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index 4603029..8074950 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -5,7 +5,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
commands :git => 'git'
- has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes, :user, :depth, :submodules
+ has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes, :user, :depth, :branch, :submodules
def create
if @resource.value(:revision) and @resource.value(:ensure) == :bare
@@ -14,13 +14,16 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
if !@resource.value(:source)
init_repository(@resource.value(:path))
else
- clone_repository(@resource.value(:source), @resource.value(:path))
+ clone_repository(default_url, @resource.value(:path))
+ update_remotes
+
if @resource.value(:revision)
checkout
end
if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true
update_submodules
end
+
end
update_owner_and_excludes
end
@@ -72,7 +75,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") }
end
#TODO Would this ever reach here if it is bare?
- if @resource.value(:ensure) != :bare
+ if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true
update_submodules
end
update_owner_and_excludes
@@ -82,9 +85,25 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
bare_git_config_exists? && !working_copy_exists?
end
+ # If :source is set to a hash (for supporting multiple remotes),
+ # we search for the URL for :remote. If it doesn't exist,
+ # we throw an error. If :source is just a string, we use that
+ # value for the default URL.
+ def default_url
+ if @resource.value(:source).is_a?(Hash)
+ if @resource.value(:source).has_key?(@resource.value(:remote))
+ @resource.value(:source)[@resource.value(:remote)]
+ else
+ fail("You must specify the URL for #{@resource.value(:remote)} in the :source hash")
+ end
+ else
+ @resource.value(:source)
+ end
+ end
+
def working_copy_exists?
if @resource.value(:source) and File.exists?(File.join(@resource.value(:path), '.git', 'config'))
- File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{@resource.value(:source)}/).any?
+ File.readlines(File.join(@resource.value(:path), '.git', 'config')).grep(/#{default_url}/).any?
else
File.directory?(File.join(@resource.value(:path), '.git'))
end
@@ -94,18 +113,54 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
working_copy_exists? || bare_exists?
end
- def update_remote_origin_url
- current = git_with_identity('config', "remote.#{@resource.value(:remote)}.url")
- unless @resource.value(:source).nil?
- if current.nil? or current.strip != @resource.value(:source)
- git_with_identity('config', "remote.#{@resource.value(:remote)}.url", @resource.value(:source))
+ def update_remote_url(remote_name, remote_url)
+ do_update = false
+ current = git_with_identity('config', '-l')
+
+ unless remote_url.nil?
+ # Check if remote exists at all, regardless of URL.
+ # If remote doesn't exist, add it
+ if not current.include? "remote.#{remote_name}.url"
+ git_with_identity('remote','add', remote_name, remote_url)
+ return true
+
+ # If remote exists, but URL doesn't match, update URL
+ elsif not current.include? "remote.#{remote_name}.url=#{remote_url}"
+ git_with_identity('remote','set-url', remote_name, remote_url)
+ return true
+ else
+ return false
+ end
+ end
+
+ end
+
+ def update_remotes
+ do_update = false
+
+ # If supplied source is a hash of remote name and remote url pairs, then
+ # we loop around the hash. Otherwise, we assume single url specified
+ # in source property
+ if @resource.value(:source).is_a?(Hash)
+ @resource.value(:source).keys.sort.each do |remote_name|
+ remote_url = @resource.value(:source)[remote_name]
+ at_path { do_update |= update_remote_url(remote_name, remote_url) }
end
+ else
+ at_path { do_update |= update_remote_url(@resource.value(:remote), @resource.value(:source)) }
+ end
+
+ # If at least one remote was added or updated, then we must
+ # call the 'git remote update' command
+ if do_update == true
+ at_path { git_with_identity('remote','update') }
end
+
end
def update_references
at_path do
- update_remote_origin_url
+ update_remotes
git_with_identity('fetch', @resource.value(:remote))
git_with_identity('fetch', '--tags', @resource.value(:remote))
update_owner_and_excludes
@@ -129,6 +184,9 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
args.push('--branch', @resource.value(:revision).to_s)
end
end
+ if @resource.value(:branch)
+ args.push('--branch', @resource.value(:branch).to_s)
+ end
if @resource.value(:ensure) == :bare
args << '--bare'
end
@@ -363,7 +421,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
# @!visibility private
def git_with_identity(*args)
if @resource.value(:identity)
- Tempfile.open('git-helper') do |f|
+ Tempfile.open('git-helper', Puppet[:statedir]) do |f|
f.puts '#!/bin/sh'
f.puts "exec ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -oConnectTimeout=120 -i #{@resource.value(:identity)} $*"
f.close
diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb
index a1b1714..905d5ad 100644
--- a/lib/puppet/provider/vcsrepo/svn.rb
+++ b/lib/puppet/provider/vcsrepo/svn.rb
@@ -7,7 +7,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo)
:svnadmin => 'svnadmin',
:svnlook => 'svnlook'
- has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration
+ has_features :filesystem_types, :reference_tracking, :basic_auth, :configuration, :conflict
def create
if !@resource.value(:source)
@@ -92,6 +92,11 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo)
else
buildargs.push('update', '-r', desired)
end
+
+ if @resource.value(:conflict)
+ args.push('--accept', @resource.value(:conflict))
+ end
+
at_path do
svn(*args)
end
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb
index 3bf4029..e5dfbb5 100644
--- a/lib/puppet/type/vcsrepo.rb
+++ b/lib/puppet/type/vcsrepo.rb
@@ -40,12 +40,18 @@ Puppet::Type.newtype(:vcsrepo) do
feature :depth,
"The provider can do shallow clones"
+ feature :branch,
+ "The name of the branch"
+
feature :p4config,
"The provider understands Perforce Configuration"
feature :submodules,
"The repository contains submodules which can be optionally initialized"
+ feature :conflict,
+ "The provider supports automatic conflict resolution"
+
ensurable do
attr_accessor :latest
@@ -204,6 +210,10 @@ Puppet::Type.newtype(:vcsrepo) do
desc "The value to be used to do a shallow clone."
end
+ newparam :branch, :required_features => [:branch] do
+ desc "The name of the branch to clone."
+ end
+
newparam :p4config, :required_features => [:p4config] do
desc "The Perforce P4CONFIG environment."
end
@@ -214,6 +224,10 @@ Puppet::Type.newtype(:vcsrepo) do
defaultto true
end
+ newparam :conflict do
+ desc "The action to take if conflicts exist between repository and working copy"
+ end
+
autorequire(:package) do
['git', 'git-core']
end