Some fixes after live testing, add support for bare cloned repos
This commit is contained in:
parent
a42116b096
commit
0a306f288e
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user