summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--.travis.yml2
-rw-r--r--CONTRIBUTING.md22
-rw-r--r--Gemfile13
-rw-r--r--README.markdown4
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb6
-rw-r--r--lib/puppet/provider/vcsrepo/svn.rb2
-rw-r--r--lib/puppet/type/vcsrepo.rb10
-rw-r--r--spec/acceptance/beaker/git/clone/negative/clone_over_different_exiting_repo.rb3
-rw-r--r--spec/acceptance/clone_repo_spec.rb17
-rw-r--r--spec/acceptance/modules_1596_spec.rb72
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb57
12 files changed, 104 insertions, 106 deletions
diff --git a/.gitignore b/.gitignore
index b5b7a00..b5db85e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,5 @@ spec/fixtures/
.vagrant/
.bundle/
coverage/
+.idea/
+*.iml
diff --git a/.travis.yml b/.travis.yml
index c72d5e2..8cfaf23 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,6 @@
---
language: ruby
-bundler_args: --without development
+bundler_args: --without system_tests
script: "bundle exec rake spec SPEC_OPTS='--format documentation'"
matrix:
fast_finish: true
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e128847..f1cbde4 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -41,11 +41,9 @@ Checklist (and a short version for the impatient)
* Pre-requisites:
- - Sign the [Contributor License Agreement](https://cla.puppetlabs.com/)
-
- Make sure you have a [GitHub account](https://github.com/join)
- - [Create a ticket](http://projects.puppetlabs.com/projects/modules/issues/new), or [watch the ticket](http://projects.puppetlabs.com/projects/modules/issues) you are patching for.
+ - [Create a ticket](https://tickets.puppetlabs.com/secure/CreateIssue!default.jspa), or [watch the ticket](https://tickets.puppetlabs.com/browse/) you are patching for.
* Preferred method:
@@ -94,17 +92,7 @@ The long version
whitespace or other "whitespace errors". You can do this by
running "git diff --check" on your changes before you commit.
- 2. Sign the Contributor License Agreement
-
- Before we can accept your changes, we do need a signed Puppet
- Labs Contributor License Agreement (CLA).
-
- You can access the CLA via the [Contributor License Agreement link](https://cla.puppetlabs.com/)
-
- If you have any questions about the CLA, please feel free to
- contact Puppet Labs via email at cla-submissions@puppetlabs.com.
-
- 3. Sending your patches
+ 2. Sending your patches
To submit your changes via a GitHub pull request, we _highly_
recommend that you have them on a topic branch, instead of
@@ -124,7 +112,7 @@ The long version
in order to open a pull request.
- 4. Update the related GitHub issue.
+ 3. Update the related GitHub issue.
If there is a GitHub issue associated with the change you
submitted, then you should update the ticket to include the
@@ -220,14 +208,12 @@ review.
Additional Resources
====================
-* [Getting additional help](http://projects.puppetlabs.com/projects/puppet/wiki/Getting_Help)
+* [Getting additional help](http://puppetlabs.com/community/get-help)
* [Writing tests](http://projects.puppetlabs.com/projects/puppet/wiki/Development_Writing_Tests)
* [Patchwork](https://patchwork.puppetlabs.com)
-* [Contributor License Agreement](https://projects.puppetlabs.com/contributor_licenses/sign)
-
* [General GitHub documentation](http://help.github.com/)
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
diff --git a/Gemfile b/Gemfile
index e960f7c..12fd363 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,15 +1,18 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"
-group :development, :test do
+group :development, :unit_tests do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
- gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
- gem 'beaker', :require => false
- gem 'beaker-rspec', :require => false
- gem 'pry', :require => false
gem 'simplecov', :require => false
+ gem 'puppet_facts', :require => false
+ gem 'json', :require => false
+end
+
+group :system_tests do
+ gem 'beaker-rspec', :require => false
+ gem 'serverspec', :require => false
end
if facterversion = ENV['FACTER_GEM_VERSION']
diff --git a/README.markdown b/README.markdown
index 062f0f7..6c6f0a5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -41,6 +41,10 @@ This module provides a single type with providers for each VCS, which can be use
##Setup
+Before you begin using vcsrepo, it's worth keeping in mind that this module will not install VCS software for you. If you are going to use this module, you must have already installed your preferred VCS.
+
+Also, this module, like Puppet generally, will not create parent directories for you. You will need to have your parent directories in place before you begin.
+
###Beginning with vcsrepo
To get started with the vcsrepo module, you must simply define the type `vcsrepo` with a path to your repository and the [type of VCS](#Usage) you're using in `provider` (in the below example, Git).
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index 9e1903c..13e0793 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -83,7 +83,11 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
end
def working_copy_exists?
- File.directory?(File.join(@resource.value(:path), '.git'))
+ 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?
+ else
+ File.directory?(File.join(@resource.value(:path), '.git'))
+ end
end
def exists?
diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb
index 316a3a1..a1b1714 100644
--- a/lib/puppet/provider/vcsrepo/svn.rb
+++ b/lib/puppet/provider/vcsrepo/svn.rb
@@ -24,7 +24,7 @@ Puppet::Type.type(:vcsrepo).provide(:svn, :parent => Puppet::Provider::Vcsrepo)
if File.directory?(@resource.value(:path))
# :path is an svn checkout
return true if File.directory?(File.join(@resource.value(:path), '.svn'))
- if File.directory?(File.join(@resource.value(:path), 'format'))
+ if File.file?(File.join(@resource.value(:path), 'format'))
# :path is an svn server
return true if svnlook('uuid', @resource.value(:path))
end
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb
index 3f34c57..3bf4029 100644
--- a/lib/puppet/type/vcsrepo.rb
+++ b/lib/puppet/type/vcsrepo.rb
@@ -103,16 +103,6 @@ Puppet::Type.newtype(:vcsrepo) do
prov = @resource.provider
if prov
if prov.working_copy_exists?
- if @resource.value(:force)
- if noop
- notice "Noop Mode - Would have deleted repository and re-created from latest"
- else
- notice "Deleting current repository before recloning"
- prov.destroy
- notice "Create repository from latest"
- prov.create
- end
- end
(@should.include?(:latest) && prov.latest?) ? :latest : :present
elsif prov.class.feature?(:bare_repositories) and prov.bare_exists?
:bare
diff --git a/spec/acceptance/beaker/git/clone/negative/clone_over_different_exiting_repo.rb b/spec/acceptance/beaker/git/clone/negative/clone_over_different_exiting_repo.rb
index 6826673..1e3b4bb 100644
--- a/spec/acceptance/beaker/git/clone/negative/clone_over_different_exiting_repo.rb
+++ b/spec/acceptance/beaker/git/clone/negative/clone_over_different_exiting_repo.rb
@@ -35,8 +35,7 @@ hosts.each do |host|
}
EOS
- apply_manifest_on(host, pp, :catch_failures => true)
- apply_manifest_on(host, pp, :catch_changes => true)
+ apply_manifest_on(host, pp, :expect_failures => true)
end
step 'verify original repo was not replaced' do
diff --git a/spec/acceptance/clone_repo_spec.rb b/spec/acceptance/clone_repo_spec.rb
index f3e77db..2cca061 100644
--- a/spec/acceptance/clone_repo_spec.rb
+++ b/spec/acceptance/clone_repo_spec.rb
@@ -327,21 +327,18 @@ describe 'clones a remote repo' do
end
context 'and noop' do
- let(:repo_name) do
- 'testrepo_already_exists'
- end
before(:all) do
- shell("mkdir #{tmpdir}/#{repo_name}")
- shell("cd #{tmpdir}/#{repo_name} && git init")
- shell("cd #{tmpdir}/#{repo_name} && touch a && git add a && git commit -m 'a'")
+ shell("mkdir #{tmpdir}/testrepo_already_exists")
+ shell("cd #{tmpdir}/testrepo_already_exists && git init")
+ shell("cd #{tmpdir}/testrepo_already_exists && touch a && git add a && git commit -m 'a'")
end
after(:all) do
- shell("rm -rf #{tmpdir}/#{repo_name}")
+ shell("rm -rf #{tmpdir}/testrepo_already_exists")
end
it 'applies the manifest' do
pp = <<-EOS
- vcsrepo { "#{tmpdir}/#{repo_name}":
+ vcsrepo { "#{tmpdir}/testrepo_already_exists":
ensure => present,
source => "file://#{tmpdir}/testrepo.git",
provider => git,
@@ -350,9 +347,7 @@ describe 'clones a remote repo' do
}
EOS
- apply_manifest(pp, :catch_changes => true) do |r|
- expect(r.stdout).to match(/Noop Mode/)
- end
+ apply_manifest(pp, :catch_changes => true)
end
end
end
diff --git a/spec/acceptance/modules_1596_spec.rb b/spec/acceptance/modules_1596_spec.rb
new file mode 100644
index 0000000..fa36285
--- /dev/null
+++ b/spec/acceptance/modules_1596_spec.rb
@@ -0,0 +1,72 @@
+require 'spec_helper_acceptance'
+
+tmpdir = default.tmpdir('vcsrepo')
+
+describe 'clones a remote repo' do
+ before(:all) do
+ my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+ shell("mkdir -p #{tmpdir}") # win test
+ end
+
+ after(:all) do
+ shell("rm -rf #{tmpdir}/vcsrepo")
+ end
+
+ context 'force with a remote' do
+ it 'clones from remote' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/vcsrepo":
+ ensure => present,
+ provider => git,
+ source => 'https://github.com/puppetlabs/puppetlabs-vcsrepo',
+ force => true,
+ }
+ EOS
+
+ # Run it twice to test for idempotency
+ apply_manifest(pp, :catch_failures => true)
+ # need to create a file to make sure we aren't destroying the repo
+ # because fun fact, if you call destroy/create in 'retrieve' puppet won't
+ # register that any changes happen, because that method isn't supposed to
+ # be making any changes.
+ shell("touch #{tmpdir}/vcsrepo/foo")
+ apply_manifest(pp, :catch_changes => true)
+ end
+
+ describe file("#{tmpdir}/vcsrepo/foo") do
+ it { is_expected.to be_file }
+ end
+ end
+
+ context 'force over an existing repo' do
+ it 'clones from remote' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/vcsrepo":
+ ensure => present,
+ provider => git,
+ source => 'https://github.com/puppetlabs/puppetlabs-vcsrepo',
+ force => true,
+ }
+ EOS
+
+ pp2 = <<-EOS
+ vcsrepo { "#{tmpdir}/vcsrepo":
+ ensure => present,
+ provider => git,
+ source => 'https://github.com/puppetlabs/puppetlabs-stdlib',
+ force => true,
+ }
+ EOS
+
+
+ apply_manifest(pp, :catch_failures => true)
+ # create a file to make sure we're destroying the repo
+ shell("touch #{tmpdir}/vcsrepo/foo")
+ apply_manifest(pp2, :catch_failures => true)
+ end
+
+ describe file("#{tmpdir}/vcsrepo/foo") do
+ it { is_expected.to_not be_file }
+ end
+ end
+end
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index 122eb62..116e357 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -175,28 +175,6 @@ branches
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
- it "should warn about destroying it using force and noop attribute" do
- resource[:force] = true
- resource[:noop] = true
- resource.delete(:revision)
- provider.expects(:working_copy_exists?).returns(true)
-
- provider.expects(:destroy).never
- provider.expects(:create).never
- Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest")
- provider.resource.retrieve
- end
- it "should warn about destroying it using force and global noop" do
- resource[:force] = true
- Puppet[:noop] = true
- resource.delete(:revision)
- provider.expects(:working_copy_exists?).returns(true)
-
- provider.expects(:destroy).never
- provider.expects(:create).never
- Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest")
- provider.resource.retrieve
- end
end
context "when the path is not empty and not a repository" do
@@ -320,41 +298,6 @@ branches
end
end
- context "checking if revision" do
- before do
- expects_chdir
- provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
- end
- context "is a local branch" do
- context "when it's listed in 'git branch -a'" do
- it "should return true" do
- resource[:revision] = 'feature/foo'
- expect(provider).to be_local_branch_revision
- end
- end
- context "when it's not listed in 'git branch -a'" do
- it "should return false" do
- resource[:revision] = 'feature/notexist'
- expect(provider).not_to be_local_branch_revision
- end
- end
- end
- context "is a remote branch" do
- context "when it's listed in 'git branch -a' with an 'origin/' prefix" do
- it "should return true" do
- resource[:revision] = 'only/remote'
- expect(provider).to be_remote_branch_revision
- end
- end
- context "when it's not listed in 'git branch -a' with an 'origin/' prefix" do
- it "should return false" do
- resource[:revision] = 'only/local'
- expect(provider).not_to be_remote_branch_revision
- end
- end
- end
- end
-
describe 'latest?' do
context 'when true' do
it do