Some fixes after live testing, add support for bare cloned repos
This commit is contained in:
@@ -5,24 +5,20 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
|
|||||||
desc "Supports Git repositories"
|
desc "Supports Git repositories"
|
||||||
|
|
||||||
commands :git => 'git'
|
commands :git => 'git'
|
||||||
|
defaultfor :git => :exists
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if !@resource.value(:source)
|
if !@resource.value(:source)
|
||||||
init_repository(@resource.value(:path))
|
init_repository(@resource.value(:path))
|
||||||
else
|
else
|
||||||
clone_repository(@resource.value(:source), @resource.value(:path))
|
clone_repository(@resource.value(:source), @resource.value(:path))
|
||||||
reset(@resource.value(:revision)) if @resource.value(:revision)
|
if @resource.value(:revision)
|
||||||
end
|
if @resource.value(:ensure) == :bare
|
||||||
end
|
notice "Ignoring revision for bare repository"
|
||||||
|
else
|
||||||
def exists?
|
reset(@resource.value(:revision))
|
||||||
case @resource.value(:ensure)
|
end
|
||||||
when 'present'
|
end
|
||||||
working_copy_exists?
|
|
||||||
when 'bare'
|
|
||||||
bare_exists?
|
|
||||||
else
|
|
||||||
path_exists?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -45,8 +41,6 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
|
|||||||
reset(desired)
|
reset(desired)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def bare_exists?
|
def bare_exists?
|
||||||
bare_git_config_exists? && !working_copy_exists?
|
bare_git_config_exists? && !working_copy_exists?
|
||||||
end
|
end
|
||||||
@@ -54,7 +48,13 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
|
|||||||
def working_copy_exists?
|
def working_copy_exists?
|
||||||
File.directory?(File.join(@resource.value(:path), '.git'))
|
File.directory?(File.join(@resource.value(:path), '.git'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exists?
|
||||||
|
bare_exists? || working_copy_exists?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def path_exists?
|
def path_exists?
|
||||||
File.directory?(@resource.value(:path))
|
File.directory?(@resource.value(:path))
|
||||||
end
|
end
|
||||||
@@ -64,7 +64,12 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def clone_repository(source, path)
|
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
|
end
|
||||||
|
|
||||||
def fetch
|
def fetch
|
||||||
@@ -74,9 +79,9 @@ Puppet::Type.type(:vcsrepo).provide(:git) do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def init_repository(path)
|
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
|
convert_working_copy_to_bare
|
||||||
elsif @resource.value(:ensure) == 'present' && bare_exists?
|
elsif @resource.value(:ensure) == :present && bare_exists?
|
||||||
convert_bare_to_working_copy
|
convert_bare_to_working_copy
|
||||||
elsif File.directory?(@resource.value(:path))
|
elsif File.directory?(@resource.value(:path))
|
||||||
raise Puppet::Error, "Could not create repository (non-repository at 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
|
def normal_init
|
||||||
FileUtils.mkdir(@resource.value(:path))
|
FileUtils.mkdir(@resource.value(:path))
|
||||||
args = ['init']
|
args = ['init']
|
||||||
if @resource.value(:ensure) == 'bare'
|
if @resource.value(:ensure) == :bare
|
||||||
|
notice "Creating a bare repository"
|
||||||
args << '--bare'
|
args << '--bare'
|
||||||
|
else
|
||||||
|
notice "Creating a working copy repository (#{@resource.value(:ensure).inspect})"
|
||||||
end
|
end
|
||||||
at_path do
|
at_path do
|
||||||
git(*args)
|
git(*args)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ Puppet::Type.type(:vcsrepo).provide(:svn) do
|
|||||||
commands :svn => 'svn',
|
commands :svn => 'svn',
|
||||||
:svnadmin => 'svnadmin'
|
:svnadmin => 'svnadmin'
|
||||||
|
|
||||||
|
defaultfor :svn => :exists
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if !@resource.value(:source)
|
if !@resource.value(:source)
|
||||||
create_repository(@resource.value(:path))
|
create_repository(@resource.value(:path))
|
||||||
|
|||||||
@@ -9,6 +9,22 @@ Puppet::Type.newtype(:vcsrepo) do
|
|||||||
newvalue :bare do
|
newvalue :bare do
|
||||||
provider.create
|
provider.create
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
newparam(:path) do
|
newparam(:path) do
|
||||||
|
|||||||
@@ -11,27 +11,55 @@ describe provider_class do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'when creating' do
|
describe 'when creating' do
|
||||||
context "when a source is given" do
|
context "and when a source is given" do
|
||||||
context "and when a revision is given" do
|
before do
|
||||||
it "should execute 'git clone' and 'git reset'" do
|
@resource.expects(:value).with(:source).returns('git://example.com/repo.git').at_least_once
|
||||||
@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
|
|
||||||
end
|
end
|
||||||
context "and when a revision is not given" do
|
context "and when ensure = present" do
|
||||||
it "should just execute 'git clone'" do
|
before do
|
||||||
@resource.expects(:value).with(:path).returns(@path).at_least_once
|
@resource.expects(:value).with(:ensure).returns(:present).at_least_once
|
||||||
@resource.expects(:value).with(:source).returns('git://example.com/repo.git').at_least_once
|
end
|
||||||
@resource.expects(:value).with(:revision).returns(nil).at_least_once
|
context "and when a revision is given" do
|
||||||
@provider.expects(:git).with('clone', 'git://example.com/repo.git', @path)
|
it "should execute 'git clone' and 'git reset'" do
|
||||||
@provider.create
|
@resource.expects(:value).with(:path).returns(@path).at_least_once
|
||||||
end
|
@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
|
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
|
end
|
||||||
context "when a source is not given" do
|
context "when a source is not given" do
|
||||||
before do
|
before do
|
||||||
@@ -39,7 +67,7 @@ describe provider_class do
|
|||||||
@resource.expects(:value).with(:source).returns(nil)
|
@resource.expects(:value).with(:source).returns(nil)
|
||||||
end
|
end
|
||||||
context "when ensure = present" do
|
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
|
context "when the path does not exist" do
|
||||||
it "should execute 'git init'" do
|
it "should execute 'git init'" do
|
||||||
Dir.expects(:mkdir).with(@path)
|
Dir.expects(:mkdir).with(@path)
|
||||||
@@ -68,7 +96,7 @@ describe provider_class do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
context "when ensure = bare" do
|
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
|
context "when the path does not exist" do
|
||||||
it "should execute 'git init --bare'" do
|
it "should execute 'git init --bare'" do
|
||||||
Dir.expects(:chdir).with(@path).yields
|
Dir.expects(:chdir).with(@path).yields
|
||||||
@@ -107,58 +135,6 @@ describe provider_class do
|
|||||||
end
|
end
|
||||||
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
|
describe "when checking the revision property" do
|
||||||
context "when given a non-SHA ref as the resource revision" 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
|
context "when its SHA is not different than the curent SHA" do
|
||||||
|
|||||||
Reference in New Issue
Block a user