summaryrefslogtreecommitdiff
path: root/lib/puppet/provider/vcsrepo/git.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/provider/vcsrepo/git.rb')
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb37
1 files changed, 32 insertions, 5 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index 66c4d07..d971e90 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)
##TODO modify the commands below so that the su - is included
optional_commands :git => 'git',
- :su => 'su'
+ :su => 'su'
has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes, :user
def create
@@ -54,9 +54,22 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
return current unless @resource.value(:revision)
if tag_revision?(@resource.value(:revision))
- canonical = at_path { git_with_identity('show', @resource.value(:revision)).scan(/commit (.*)/).to_s }
+ canonical = at_path { git_with_identity('show', @resource.value(:revision)).scan(/^commit (.*)/).to_s }
else
- canonical = at_path { git_with_identity('rev-parse', @resource.value(:revision)).chomp }
+ # if it's not a tag, look for it as a local ref
+ canonical = at_path { git_with_identity('rev-parse', '--revs-only', @resource.value(:revision)).chomp }
+ if canonical.empty?
+ # git rev-parse executed properly but didn't find the ref;
+ # look for it in the remote
+ remote_ref = at_path { git_with_identity('ls-remote', '--heads', '--tags', @resource.value(:remote), @resource.value(:revision)).chomp }
+ if remote_ref.empty?
+ fail("#{@resource.value(:revision)} is not a local or remote ref")
+ end
+
+ # $ git ls-remote --heads --tags origin feature/cvs
+ # 7d4244b35e72904e30130cad6d2258f901c16f1a refs/heads/feature/cvs
+ canonical = remote_ref.split.first
+ end
end
if current == canonical
@@ -93,8 +106,18 @@ 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.origin.url')
+ unless @resource.value(:source).nil?
+ if current.nil? or current.strip != @resource.value(:source)
+ git_with_identity('config', 'remote.origin.url', @resource.value(:source))
+ end
+ end
+ end
+
def update_references
at_path do
+ update_remote_origin_url
git_with_identity('fetch', @resource.value(:remote))
git_with_identity('fetch', '--tags', @resource.value(:remote))
update_owner_and_excludes
@@ -115,7 +138,9 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end
if !File.exist?(File.join(@resource.value(:path), '.git'))
args.push(source, path)
- git_with_identity(*args)
+ Dir.chdir("/") do
+ git_with_identity(*args)
+ end
else
notice "Repo has already been cloned"
end
@@ -141,6 +166,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
else
# normal init
FileUtils.mkdir(@resource.value(:path))
+ FileUtils.chown(@resource.value(:user), nil, @resource.value(:path)) if @resource.value(:user)
args = ['init']
if @resource.value(:ensure) == :bare
args << '--bare'
@@ -247,6 +273,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
create
end
at_path do
+ update_remote_origin_url
git_with_identity('fetch', @resource.value(:remote))
git_with_identity('fetch', '--tags', @resource.value(:remote))
end
@@ -276,7 +303,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
if @resource.value(:identity)
Tempfile.open('git-helper') do |f|
f.puts '#!/bin/sh'
- f.puts "exec ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -i #{@resource.value(:identity)} $*"
+ f.puts "exec ssh -oStrictHostKeyChecking=no -oPasswordAuthentication=no -oKbdInteractiveAuthentication=no -oChallengeResponseAuthentication=no -oConnectTimeout=120 -i #{@resource.value(:identity)} $*"
f.close
FileUtils.chmod(0755, f.path)