summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Williams <bruce@codefluency.com>2010-03-13 01:05:20 -0800
committerBruce Williams <bruce@codefluency.com>2010-03-13 01:05:20 -0800
commit0a306f288e84bed857e4d82c695dcea0c6ceb37a (patch)
treeec3cb866b00034edc140aefc5622673cf7d3fde7
parenta42116b0968cc2f7fe1714564c969ad4674f4f69 (diff)
downloadpuppet-vcsrepo-0a306f288e84bed857e4d82c695dcea0c6ceb37a.tar.gz
puppet-vcsrepo-0a306f288e84bed857e4d82c695dcea0c6ceb37a.tar.bz2
Some fixes after live testing, add support for bare cloned repos
-rw-r--r--lib/puppet/provider/vcsrepo/git.rb44
-rw-r--r--lib/puppet/provider/vcsrepo/svn.rb2
-rw-r--r--lib/puppet/type/vcsrepo.rb16
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb122
4 files changed, 93 insertions, 91 deletions
diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb
index bdc819e..ec58515 100644
--- a/lib/puppet/provider/vcsrepo/git.rb
+++ b/lib/puppet/provider/vcsrepo/git.rb
@@ -5,24 +5,20 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
desc "Supports Git repositories"
commands :git => 'git'
+ defaultfor :git => :exists
def create
if !@resource.value(:source)
init_repository(@resource.value(:path))
else
clone_repository(@resource.value(:source), @resource.value(:path))
- reset(@resource.value(:revision)) if @resource.value(:revision)
- end
- end
-
- def exists?
- case @resource.value(:ensure)
- when 'present'
- working_copy_exists?
- when 'bare'
- bare_exists?
- else
- path_exists?
+ if @resource.value(:revision)
+ if @resource.value(:ensure) == :bare
+ notice "Ignoring revision for bare repository"
+ else
+ reset(@resource.value(:revision))
+ end
+ end
end
end
@@ -45,8 +41,6 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
reset(desired)
end
- private
-
def bare_exists?
bare_git_config_exists? && !working_copy_exists?
end
@@ -54,7 +48,13 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
def working_copy_exists?
File.directory?(File.join(@resource.value(:path), '.git'))
end
+
+ def exists?
+ bare_exists? || working_copy_exists?
+ end
+ private
+
def path_exists?
File.directory?(@resource.value(:path))
end
@@ -64,7 +64,12 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
end
def clone_repository(source, path)
- git('clone', source, path)
+ args = ['clone']
+ if @resource.value(:ensure) == :bare
+ args << '--bare'
+ end
+ args.push(source, path)
+ git(*args)
end
def fetch
@@ -74,9 +79,9 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
end
def init_repository(path)
- if @resource.value(:ensure) == 'bare' && working_copy_exists?
+ if @resource.value(:ensure) == :bare && working_copy_exists?
convert_working_copy_to_bare
- elsif @resource.value(:ensure) == 'present' && bare_exists?
+ elsif @resource.value(:ensure) == :present && bare_exists?
convert_bare_to_working_copy
elsif File.directory?(@resource.value(:path))
raise Puppet::Error, "Could not create repository (non-repository at path)"
@@ -114,8 +119,11 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
def normal_init
FileUtils.mkdir(@resource.value(:path))
args = ['init']
- if @resource.value(:ensure) == 'bare'
+ if @resource.value(:ensure) == :bare
+ notice "Creating a bare repository"
args << '--bare'
+ else
+ notice "Creating a working copy repository (#{@resource.value(:ensure).inspect})"
end
at_path do
git(*args)
diff --git a/lib/puppet/provider/vcsrepo/svn.rb b/lib/puppet/provider/vcsrepo/svn.rb
index 0e38769..226cc63 100644
--- a/lib/puppet/provider/vcsrepo/svn.rb
+++ b/lib/puppet/provider/vcsrepo/svn.rb
@@ -4,6 +4,8 @@ Puppet::Type.type(:vcsrepo).provide(:svn) do
commands :svn => 'svn',
:svnadmin => 'svnadmin'
+ defaultfor :svn => :exists
+
def create
if !@resource.value(:source)
create_repository(@resource.value(:path))
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb
index 4d5c2a0..b093910 100644
--- a/lib/puppet/type/vcsrepo.rb
+++ b/lib/puppet/type/vcsrepo.rb
@@ -9,6 +9,22 @@ Puppet::Type.newtype(:vcsrepo) do
newvalue :bare do
provider.create
end
+
+ def retrieve
+ prov = @resource.provider
+ if prov
+ if prov.respond_to?(:working_copy_exists?) && prov.working_copy_exists?
+ :present
+ elsif prov.respond_to?(:bare_exists?) && prov.bare_exists?
+ :bare
+ else
+ :absent
+ end
+ else
+ :absent
+ end
+ end
+
end
newparam(:path) do
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index f8a7170..5cf6c86 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -11,27 +11,55 @@ describe provider_class do
end
describe 'when creating' do
- context "when a source is given" do
- context "and when a revision is given" do
- it "should execute 'git clone' and 'git reset'" do
- @resource.expects(:value).with(:path).returns(@path).at_least_once
- @resource.expects(:value).with(:source).returns('git://example.com/repo.git').at_least_once
- @provider.expects(:git).with('clone', 'git://example.com/repo.git', @path)
- @resource.expects(:value).with(:revision).returns('abcdef').at_least_once
- Dir.expects(:chdir).with(@path).yields
- @provider.expects('git').with('reset', '--hard', 'abcdef')
- @provider.create
- end
+ context "and when a source is given" do
+ before do
+ @resource.expects(:value).with(:source).returns('git://example.com/repo.git').at_least_once
end
- context "and when a revision is not given" do
- it "should just execute 'git clone'" do
- @resource.expects(:value).with(:path).returns(@path).at_least_once
- @resource.expects(:value).with(:source).returns('git://example.com/repo.git').at_least_once
- @resource.expects(:value).with(:revision).returns(nil).at_least_once
- @provider.expects(:git).with('clone', 'git://example.com/repo.git', @path)
- @provider.create
- end
+ context "and when ensure = present" do
+ before do
+ @resource.expects(:value).with(:ensure).returns(:present).at_least_once
+ end
+ context "and when a revision is given" do
+ it "should execute 'git clone' and 'git reset'" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @provider.expects(:git).with('clone', 'git://example.com/repo.git', @path)
+ @resource.expects(:value).with(:revision).returns('abcdef').at_least_once
+ Dir.expects(:chdir).with(@path).yields
+ @provider.expects('git').with('reset', '--hard', 'abcdef')
+ @provider.create
+ end
+ end
+ context "and when a revision is not given" do
+ it "should just execute 'git clone'" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @resource.expects(:value).with(:revision).returns(nil).at_least_once
+ @provider.expects(:git).with('clone', 'git://example.com/repo.git', @path)
+ @provider.create
+ end
+ end
end
+ context "and when ensure = bare" do
+ before do
+ @resource.expects(:value).with(:ensure).returns(:bare).at_least_once
+ end
+ context "and when a revision is given" do
+ it "should just execute 'git clone --bare'" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @resource.expects(:value).with(:revision).returns(nil).at_least_once
+ @provider.expects(:git).with('clone', '--bare', 'git://example.com/repo.git', @path)
+ @provider.create
+ end
+ end
+ context "and when a revision is not given" do
+ it "should just execute 'git clone --bare'" do
+ @resource.expects(:value).with(:path).returns(@path).at_least_once
+ @resource.expects(:value).with(:revision).returns(nil).at_least_once
+ @provider.expects(:git).with('clone', '--bare', 'git://example.com/repo.git', @path)
+ @provider.create
+ end
+ end
+ end
+
end
context "when a source is not given" do
before do
@@ -39,7 +67,7 @@ describe provider_class do
@resource.expects(:value).with(:source).returns(nil)
end
context "when ensure = present" do
- before { @resource.expects(:value).with(:ensure).returns('present').at_least_once }
+ before { @resource.expects(:value).with(:ensure).returns(:present).at_least_once }
context "when the path does not exist" do
it "should execute 'git init'" do
Dir.expects(:mkdir).with(@path)
@@ -68,7 +96,7 @@ describe provider_class do
end
end
context "when ensure = bare" do
- before { @resource.expects(:value).with(:ensure).returns('bare').at_least_once }
+ before { @resource.expects(:value).with(:ensure).returns(:bare).at_least_once }
context "when the path does not exist" do
it "should execute 'git init --bare'" do
Dir.expects(:chdir).with(@path).yields
@@ -107,58 +135,6 @@ describe provider_class do
end
end
- describe "when checking existence" do
- context "when ensure = present" do
- context "when a working copy exists" do
- it "should be true" do
- @resource.expects(:value).with(:ensure).returns('present').at_least_once
- @provider.expects(:working_copy_exists?).returns(true)
- @provider.should be_exists
- end
- end
- context "when a bare repo exists" do
- it "should be " do
- @resource.expects(:value).with(:ensure).returns('present').at_least_once
- @provider.expects(:working_copy_exists?).returns(false)
- @provider.should_not be_exists
- end
- end
- end
- context "when ensure = bare" do
- context "when a working copy exists" do
- it "should be false" do
- @resource.expects(:value).with(:ensure).returns('bare').at_least_once
- @provider.expects(:bare_exists?).returns(false)
- @provider.should_not be_exists
- end
- end
- context "when a bare repo exists" do
- it "should be true" do
- @resource.expects(:value).with(:ensure).returns('bare').at_least_once
- @provider.expects(:bare_exists?).returns(true)
- @provider.should be_exists
- end
- end
- end
- context "when ensure = absent" do
- before { @resource.expects(:value).with(:ensure).returns('absent') }
- context "when the path exists" do
- it "should be true" do
- @resource.expects(:value).with(:path).returns(@path)
- File.expects(:directory?).with(@path).returns(true)
- @provider.should be_exists
- end
- end
- context "when the path does not exist" do
- it "should be false" do
- @resource.expects(:value).with(:path).returns(@path)
- File.expects(:directory?).with(@path).returns(false)
- @provider.should_not be_exists
- end
- end
- end
- end
-
describe "when checking the revision property" do
context "when given a non-SHA ref as the resource revision" do
context "when its SHA is not different than the curent SHA" do