Add the ability to specify a git remote
Rather than fill the git provider with hard-coded references to origin, it would be better to abstract out which remote the resource is fetching from. But since this is only relevant to decentralized version-control systems, a multiple_remotes feature was added for the parameter to depend on. So far this is only implemented for git remotes, but it could be implemented for other VCSs as well.
This commit is contained in:
@@ -6,7 +6,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
|
|||||||
##TODO modify the commands below so that the su - is included
|
##TODO modify the commands below so that the su - is included
|
||||||
optional_commands :git => 'git'
|
optional_commands :git => 'git'
|
||||||
defaultfor :git => :exists
|
defaultfor :git => :exists
|
||||||
has_features :bare_repositories, :reference_tracking, :ssh_identity
|
has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if !@resource.value(:source)
|
if !@resource.value(:source)
|
||||||
@@ -40,11 +40,11 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
|
|||||||
def latest
|
def latest
|
||||||
branch = on_branch?
|
branch = on_branch?
|
||||||
if branch == 'master'
|
if branch == 'master'
|
||||||
return get_revision('origin/HEAD')
|
return get_revision("#{@resource.value(:remote)}/HEAD")
|
||||||
elsif branch == '(no branch)'
|
elsif branch == '(no branch)'
|
||||||
return get_revision('HEAD')
|
return get_revision('HEAD')
|
||||||
else
|
else
|
||||||
return get_revision('origin/%s' % branch)
|
return get_revision("#{@resource.value(:remote)}/%s" % branch)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
|
|||||||
# authoritative.
|
# authoritative.
|
||||||
# might be worthwhile to have an allow_local_changes param to decide
|
# might be worthwhile to have an allow_local_changes param to decide
|
||||||
# whether to reset or pull when we're ensuring latest.
|
# whether to reset or pull when we're ensuring latest.
|
||||||
at_path { git_with_identity('reset', '--hard', "origin/#{desired}") }
|
at_path { git_with_identity('reset', '--hard', "#{@resource.value(:remote)}/#{desired}") }
|
||||||
end
|
end
|
||||||
if @resource.value(:ensure) != :bare
|
if @resource.value(:ensure) != :bare
|
||||||
update_submodules
|
update_submodules
|
||||||
@@ -95,7 +95,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
|
|||||||
|
|
||||||
def update_references
|
def update_references
|
||||||
at_path do
|
at_path do
|
||||||
git_with_identity('fetch', '--tags', 'origin')
|
git_with_identity('fetch', '--tags', @resource.value(:remote))
|
||||||
update_owner_and_excludes
|
update_owner_and_excludes
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -190,7 +190,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
|
|||||||
|
|
||||||
def checkout(revision = @resource.value(:revision))
|
def checkout(revision = @resource.value(:revision))
|
||||||
if !local_branch_revision? && remote_branch_revision?
|
if !local_branch_revision? && remote_branch_revision?
|
||||||
at_path { git_with_identity('checkout', '-b', revision, '--track', "origin/#{revision}") }
|
at_path { git_with_identity('checkout', '-b', revision, '--track', "#{@resource.value(:remote)}/#{revision}") }
|
||||||
else
|
else
|
||||||
at_path { git_with_identity('checkout', '--force', revision) }
|
at_path { git_with_identity('checkout', '--force', revision) }
|
||||||
end
|
end
|
||||||
@@ -212,9 +212,9 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remote_branch_revision?(revision = @resource.value(:revision))
|
def remote_branch_revision?(revision = @resource.value(:revision))
|
||||||
# git < 1.6 returns 'origin/#{revision}'
|
# git < 1.6 returns '#{@resource.value(:remote)}/#{revision}'
|
||||||
# git 1.6+ returns 'remotes/origin/#{revision}'
|
# git 1.6+ returns 'remotes/#{@resource.value(:remote)}/#{revision}'
|
||||||
branch = at_path { branches.grep /(remotes\/)?origin\/#{revision}/ }
|
branch = at_path { branches.grep /(remotes\/)?#{@resource.value(:remote)}\/#{revision}/ }
|
||||||
if branch.length > 0
|
if branch.length > 0
|
||||||
return branch
|
return branch
|
||||||
end
|
end
|
||||||
@@ -249,15 +249,15 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
|
|||||||
create
|
create
|
||||||
end
|
end
|
||||||
at_path do
|
at_path do
|
||||||
git_with_identity('fetch', 'origin')
|
git_with_identity('fetch', @resource.value(:remote))
|
||||||
git_with_identity('fetch', '--tags', 'origin')
|
git_with_identity('fetch', '--tags', @resource.value(:remote))
|
||||||
end
|
end
|
||||||
current = at_path { git_with_identity('rev-parse', rev).strip }
|
current = at_path { git_with_identity('rev-parse', rev).strip }
|
||||||
if @resource.value(:revision)
|
if @resource.value(:revision)
|
||||||
if local_branch_revision?
|
if local_branch_revision?
|
||||||
canonical = at_path { git_with_identity('rev-parse', @resource.value(:revision)).strip }
|
canonical = at_path { git_with_identity('rev-parse', @resource.value(:revision)).strip }
|
||||||
elsif remote_branch_revision?
|
elsif remote_branch_revision?
|
||||||
canonical = at_path { git_with_identity('rev-parse', 'origin/' + @resource.value(:revision)).strip }
|
canonical = at_path { git_with_identity('rev-parse', "#{@resource.value(:remote)}/" + @resource.value(:revision)).strip }
|
||||||
end
|
end
|
||||||
current = @resource.value(:revision) if current == canonical
|
current = @resource.value(:revision) if current == canonical
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ Puppet::Type.newtype(:vcsrepo) do
|
|||||||
feature :modules,
|
feature :modules,
|
||||||
"The repository contains modules that can be chosen of"
|
"The repository contains modules that can be chosen of"
|
||||||
|
|
||||||
|
feature :multiple_remotes,
|
||||||
|
"The repository tracks multiple remote repositories"
|
||||||
|
|
||||||
ensurable do
|
ensurable do
|
||||||
attr_accessor :latest
|
attr_accessor :latest
|
||||||
|
|
||||||
@@ -89,7 +92,7 @@ Puppet::Type.newtype(:vcsrepo) do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
newparam(:path) do
|
newparam :path do
|
||||||
desc "Absolute path to repository"
|
desc "Absolute path to repository"
|
||||||
isnamevar
|
isnamevar
|
||||||
validate do |value|
|
validate do |value|
|
||||||
@@ -100,32 +103,32 @@ Puppet::Type.newtype(:vcsrepo) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newparam(:source) do
|
newparam :source do
|
||||||
desc "The source URI for the repository"
|
desc "The source URI for the repository"
|
||||||
end
|
end
|
||||||
|
|
||||||
newparam(:fstype, :required_features => [:filesystem_types]) do
|
newparam :fstype, :required_features => [:filesystem_types] do
|
||||||
desc "Filesystem type"
|
desc "Filesystem type"
|
||||||
end
|
end
|
||||||
|
|
||||||
newproperty(:revision) do
|
newproperty :revision do
|
||||||
desc "The revision of the repository"
|
desc "The revision of the repository"
|
||||||
newvalue(/^\S+$/)
|
newvalue(/^\S+$/)
|
||||||
end
|
end
|
||||||
|
|
||||||
newparam(:owner) do
|
newparam :owner do
|
||||||
desc "The user/uid that owns the repository files"
|
desc "The user/uid that owns the repository files"
|
||||||
end
|
end
|
||||||
|
|
||||||
newparam(:group) do
|
newparam :group do
|
||||||
desc "The group/gid that owns the repository files"
|
desc "The group/gid that owns the repository files"
|
||||||
end
|
end
|
||||||
|
|
||||||
newparam(:excludes) do
|
newparam :excludes do
|
||||||
desc "Files to be excluded from the repository"
|
desc "Files to be excluded from the repository"
|
||||||
end
|
end
|
||||||
|
|
||||||
newparam(:force) do
|
newparam :force do
|
||||||
desc "Force repository creation, destroying any files on the path in the process."
|
desc "Force repository creation, destroying any files on the path in the process."
|
||||||
newvalues(:true, :false)
|
newvalues(:true, :false)
|
||||||
defaultto false
|
defaultto false
|
||||||
@@ -155,4 +158,10 @@ Puppet::Type.newtype(:vcsrepo) do
|
|||||||
newparam :module, :required_features => [:modules] do
|
newparam :module, :required_features => [:modules] do
|
||||||
desc "The repository module to manage"
|
desc "The repository module to manage"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
newparam :remote, :required_features => [:multiple_remotes] do
|
||||||
|
desc "The remote repository to track"
|
||||||
|
defaultto "origin"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user