}
~~~
+If you want to clone your repository as bare or mirror, you can set `ensure` to 'bare' or 'mirror':
+
+~~~
+vcsrepo { '/path/to/repo':
+ ensure => mirror,
+ provider => git,
+ source => 'git://example.com/repo.git',
+}
+~~~
+
By default, `vcsrepo` will use the HEAD of the source repository's master branch. To use another branch or a specific commit, set `revision` to either a branch name or a commit SHA or tag.
Branch name:
has_features :bare_repositories, :reference_tracking, :ssh_identity, :multiple_remotes, :user, :depth, :branch, :submodules
def create
- if @resource.value(:revision) and @resource.value(:ensure) == :bare
+ if @resource.value(:revision) and ensure_bare_or_mirror?
fail("Cannot set a revision (#{@resource.value(:revision)}) on a bare repository")
end
if !@resource.value(:source)
+ if @resource.value(:ensure) == :mirror
+ fail("Cannot init repository with mirror option, try bare instead")
+ end
+
init_repository(@resource.value(:path))
else
clone_repository(default_url, @resource.value(:path))
if @resource.value(:revision)
checkout
end
- if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true
+ if !ensure_bare_or_mirror? && @resource.value(:submodules) == :true
update_submodules
end
end
end
#TODO Would this ever reach here if it is bare?
- if @resource.value(:ensure) != :bare && @resource.value(:submodules) == :true
+ if !ensure_bare_or_mirror? && @resource.value(:submodules) == :true
update_submodules
end
update_owner_and_excludes
bare_git_config_exists? && !working_copy_exists?
end
+ def ensure_bare_or_mirror?
+ [:bare, :mirror].include? @resource.value(:ensure)
+ end
+
# If :source is set to a hash (for supporting multiple remotes),
# we search for the URL for :remote. If it doesn't exist,
# we throw an error. If :source is just a string, we use that
if @resource.value(:branch)
args.push('--branch', @resource.value(:branch).to_s)
end
- if @resource.value(:ensure) == :bare
- args << '--bare'
+
+ case @resource.value(:ensure)
+ when :bare then args << '--bare'
+ when :mirror then args << '--mirror'
end
+
if @resource.value(:remote) != 'origin'
args.push('--origin', @resource.value(:remote))
end
remote/origin/foo
branches
- end
+ end
let(:resource) { Puppet::Type.type(:vcsrepo).new({
:name => 'test',
:ensure => :present,
end
end
+ context "with an ensure of mirror" do
+ context "with revision" do
+ it "should raise an error" do
+ resource[:ensure] = :mirror
+ expect { provider.create }.to raise_error Puppet::Error, /cannot set a revision.+bare/i
+ end
+ end
+ context "without revision" do
+ it "should just execute 'git clone --mirror'" do
+ resource[:ensure] = :mirror
+ resource.delete(:revision)
+ provider.expects(:git).with('clone', '--mirror', resource.value(:source), resource.value(:path))
+ provider.expects(:update_remotes)
+ provider.create
+ end
+ end
+ end
+
context "when a source is not given" do
context "when the path does not exist" do
it "should execute 'git init'" do
provider.expects(:git).with('init', '--bare')
provider.create
end
+
+ it "should raise an exeption" do
+ resource[:ensure] = :mirror
+ resource.delete(:source)
+ resource.delete(:revision)
+
+ expect { provider.create }.to raise_error Puppet::Error, /cannot init repository with mirror.+try bare/i
+ end
end
context "when the path is a working copy repository" do