diff options
-rw-r--r-- | .travis.yml | 25 | ||||
-rw-r--r-- | Gemfile | 6 | ||||
-rw-r--r-- | Gemfile.lock | 14 | ||||
-rw-r--r-- | Modulefile | 4 | ||||
-rw-r--r-- | README.GIT.markdown | 12 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/bzr.rb | 20 | ||||
-rw-r--r-- | lib/puppet/provider/vcsrepo/git.rb | 20 | ||||
-rw-r--r-- | spec/unit/puppet/provider/vcsrepo/git_spec.rb | 17 |
8 files changed, 100 insertions, 18 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f349b8d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,25 @@ +--- +branches: + only: + - master +notifications: + email: false +language: ruby +script: 'bundle exec rake spec' +after_success: +- git clone -q git://github.com/puppetlabs/ghpublisher.git .forge-releng +- .forge-releng/publish +rvm: +- 1.8.7 +- 1.9.3 +env: + matrix: + - PUPPET_VERSION=2.6.18 + - PUPPET_VERSION=2.7.21 + - PUPPET_VERSION=3.1.1 + global: + - PUBLISHER_LOGIN=puppetlabs + - secure: |- + ZiIkYd9+CdPzpwSjFPnVkCx1FIlipxpbdyD33q94h2Tj5zXjNb1GXizVy0NR + kVxGhU5Ld8y9z8DTqKRgCI1Yymg3H//OU++PKLOQj/X5juWVR4URBNPeBOzu + IJBDl1MADKA4i1+jAZPpz4mTvTtKS4pWKErgCSmhSfsY1hs7n6c= @@ -1,5 +1,5 @@ -source :rubygems +source 'https://rubygems.org' gem 'rake', '~> 0.8.7' -gem 'rspec', '~> 1.2.9' -gem 'mocha', '~> 0.12.7', :require => false +gem 'rspec', '~> 1.3' +gem 'mocha', '~> 0.12.9', :require => false gem 'puppet', '~> 2.7' diff --git a/Gemfile.lock b/Gemfile.lock index 210a2dd..ce22804 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,20 +1,20 @@ GEM - remote: http://rubygems.org/ + remote: https://rubygems.org/ specs: - facter (1.6.13) + facter (1.7.2) metaclass (0.0.1) - mocha (0.12.7) + mocha (0.12.10) metaclass (~> 0.0.1) - puppet (2.7.19) + puppet (2.7.22) facter (~> 1.5) rake (0.8.7) - rspec (1.2.9) + rspec (1.3.2) PLATFORMS ruby DEPENDENCIES - mocha (~> 0.12.7) + mocha (~> 0.12.9) puppet (~> 2.7) rake (~> 0.8.7) - rspec (~> 1.2.9) + rspec (~> 1.3) @@ -1,2 +1,4 @@ name 'puppetlabs/vcsrepo' -version '0.1.1' +version '0.1.2' +summary 'Manage repositories from various version control systems' +description 'Manage repositories from various version control systems' diff --git a/README.GIT.markdown b/README.GIT.markdown index d6b8afe..846bdcc 100644 --- a/README.GIT.markdown +++ b/README.GIT.markdown @@ -76,9 +76,15 @@ Keep the repository at the latest revision (note: this will always overwrite loc For sources that use SSH (eg, `username@server:...`) ---------------------------------------------------- -Manage your SSH keys with Puppet and use `require` in your `vcsrepo` -to ensure they are present. For more information, see the `require` -metaparameter documentation[1]. +If your SSH key is associated with a user, simply fill the `user` parameter to use his keys. + +Example: + + user => 'toto' # will use toto's $HOME/.ssh setup + + +Otherwise, manage your SSH keys with Puppet and use `require` in your `vcsrepo` to ensure they are present. +For more information, see the `require` metaparameter documentation[1]. More Examples ------------- diff --git a/lib/puppet/provider/vcsrepo/bzr.rb b/lib/puppet/provider/vcsrepo/bzr.rb index 6169929..fff25b3 100644 --- a/lib/puppet/provider/vcsrepo/bzr.rb +++ b/lib/puppet/provider/vcsrepo/bzr.rb @@ -45,7 +45,25 @@ Puppet::Type.type(:vcsrepo).provide(:bzr, :parent => Puppet::Provider::Vcsrepo) end def revision=(desired) - bzr('update', '-r', desired, @resource.value(:path)) + at_path do + begin + bzr('update', '-r', desired) + rescue Puppet::ExecutionFailure + bzr('update', '-r', desired, ':parent') + end + end + end + + def latest + at_path do + bzr('version-info', ':parent')[/^revision-id:\s+(\S+)/, 1] + end + end + + def latest? + at_path do + return self.revision == self.latest + end end private diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index 9254243..76fa315 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -54,7 +54,7 @@ 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 } end @@ -93,8 +93,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 +125,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 +153,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' @@ -250,6 +263,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 @@ -279,7 +293,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) diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 83dbff2..4e4d9f3 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -127,6 +127,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "when its SHA is not different than the current SHA" do it "should return the ref" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('fetch', 'origin') # FIXME provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') @@ -137,6 +138,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "when its SHA is different than the current SHA" do it "should return the current SHA" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('fetch', 'origin') # FIXME provider.expects(:git).with('fetch', '--tags', 'origin') provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha') @@ -144,6 +146,20 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.revision.should == 'currentsha' end end + + context "when the source is modified" do + resource_with :source => 'git://git@foo.com/bar.git' do + it "should update the origin url" do + provider.expects(:git).with('config', 'remote.origin.url').returns('old') + provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git') + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') + provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha') + provider.expects(:git).with('tag', '-l').returns("Hello") + provider.revision.should == resource.value(:revision) + end + end + end end end @@ -189,6 +205,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "updating references" do it "should use 'git fetch --tags'" do expects_chdir + provider.expects(:git).with('config', 'remote.origin.url').returns('') provider.expects(:git).with('fetch', 'origin') provider.expects(:git).with('fetch', '--tags', 'origin') provider.update_references |