def destroy
FileUtils.rm_rf(@resource.value(:path))
end
-
+
def revision
at_path do
current_revid = bzr('version-info')[/^revision-id:\s+(\S+)/, 1]
optional_commands :cvs => 'cvs'
has_features :gzip_compression, :reference_tracking, :modules
-
+
def create
if !@resource.value(:source)
create_repository(@resource.value(:path))
def working_copy_exists?
File.directory?(File.join(@resource.value(:path), 'CVS'))
end
-
+
def destroy
FileUtils.rm_rf(@resource.value(:path))
end
- def latest?
+ def latest?
debug "Checking for updates because 'ensure => latest'"
at_path do
# We cannot use -P to prune empty dirs, otherwise
return is_current
end
end
-
+
def latest
# CVS does not have a conecpt like commit-IDs or change
- # sets, so we can only have the current branch name (or the
+ # sets, so we can only have the current branch name (or the
# requested one, if that differs) as the "latest" revision.
should = @resource.value(:revision)
current = self.revision
set_ownership
end
end
-
+
end
end
end
end
-
+
def buildargs
args = ['--non-interactive']
if @resource.value(:basic_auth_username) && @resource.value(:basic_auth_password)
svn(*args)[/^Last Changed Rev:\s+(\d+)/m, 1]
end
end
-
+
def revision
args = buildargs.push('info')
at_path do
feature :ssh_identity,
"The provider supports a configurable SSH identity file"
-
+
feature :user,
"The provider can run as a different user"
newparam :identity, :required_features => [:ssh_identity] do
desc "SSH identity file"
end
-
+
newparam :module, :required_features => [:modules] do
desc "The repository module to manage"
end
def expects_chdir(path = resource.value(:path))
Dir.expects(:chdir).with(path).at_least_once.yields
end
-
+
def expects_mkdir(path = resource.value(:path))
Dir.expects(:mkdir).with(path).at_least_once
end
def fixture(name, ext = '.txt')
File.read(File.join(File.dirname(__FILE__), '..', 'fixtures', name.to_s + ext))
end
-
+
end
# Build the provider
subject { described_class.new(@resource) }
-
+
# Allow access to it via +provider+
alias :provider :subject
context("and with a #{text}", {:resource => placeholders}, &block)
end
end
-
+
def self.build_value_context(params = {}, &block) #:nodoc:
unless params.empty?
text = params.map { |k, v| "#{k} => #{v.inspect}" }.join(' and with ')
context("and with #{text}", {:resource => params}, &block)
end
end
-
+
# Generate a context for a provider operating on a resource without
# a given parameter/property.
end
end
end
-
+
describe "setting the revision property" do
it "should use 'bzr update -r' with the revision" do
revision = 'somerev'
expects_chdir(File.dirname(resource.value(:path)))
#provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.')
provider.create
- end
+ end
end
-
+
resource_without :revision do
it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create
- end
+ end
end
-
+
context "with a compression", :resource => {:compression => '3'} do
it "should just execute 'cvs checkout' without a revision" do
provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source)))
provider.create
- end
+ end
end
end
-
+
context "when a source is not given" do
it "should execute 'cvs init'" do
provider.expects(:cvs).with('-d', resource.value(:path), 'init')
provider.exists?
end
end
-
+
resource_without :source do
it "should check for the CVSROOT directory" do
File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT'))
before do
@tag_file = File.join(resource.value(:path), 'CVS', 'Tag')
end
-
+
context "when CVS/Tag exists" do
before do
@tag = 'TAG'
provider.revision.should == @tag
end
end
-
+
context "when CVS/Tag does not exist" do
before do
File.expects(:exist?).with(@tag_file).returns(false)
end
end
end
-
+
describe "when setting the revision property" do
before do
@tag = 'SOMETAG'
end
-
+
it "should use 'cvs update -dr'" do
expects_chdir
provider.expects('cvs').with('update', '-dr', @tag, '.')
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
end
- end
+ end
resource_without :revision do
it "should execute 'git clone' and submodule commands" do
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
end
end
end
-
+
resource_with :ensure => :bare do
resource_with :revision do
it "should just execute 'git clone --bare'" do
provider.create
end
end
-
+
resource_without :revision do
it "should just execute 'git clone --bare'" do
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
end
end
end
-
+
context "when a source is not given" do
resource_with :ensure => :present do
context "when the path does not exist" do
provider.create
end
end
-
+
context "when the path is a bare repository" do
it "should convert it to a working copy" do
provider.expects(:bare_exists?).returns(true)
provider.create
end
end
-
+
context "when the path is not a repository" do
it "should raise an exception" do
provider.expects(:path_exists?).returns(true)
end
end
end
-
+
resource_with :ensure => :bare do
context "when the path does not exist" do
it "should execute 'git init --bare'" do
provider.create
end
end
-
+
context "when the path is a working copy repository" do
it "should convert it to a bare repository" do
provider.expects(:working_copy_exists?).returns(true)
provider.create
end
end
-
+
context "when the path is not a repository" do
it "should raise an exception" do
expects_directory?(true)
end
end
-
+
context 'destroying' do
it "it should remove the directory" do
expects_rm_rf
provider.destroy
end
end
-
+
context "checking the revision property" do
resource_with :revision do
before do
expects_chdir
provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha')
end
-
+
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
provider.expects(:git).with('fetch', 'origin') # FIXME
provider.revision.should == resource.value(:revision)
end
end
-
+
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
provider.expects(:git).with('fetch', 'origin') # FIXME
end
end
end
-
+
context "setting the revision property" do
before do
expects_chdir
provider.expects(:git).with('submodule', 'foreach', 'git', 'submodule', 'update')
provider.revision = resource.value(:revision)
end
- end
+ end
end
-
+
context "updating references" do
it "should use 'git fetch --tags'" do
expects_chdir
provider.should_not be_remote_branch_revision
end
end
- end
+ end
end
-
+
end
resource.value(:source),
resource.value(:path))
provider.create
- end
+ end
end
-
+
resource_without :revision do
it "should just execute 'hg clone' without a revision" do
provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path))
provider.create
- end
+ end
end
end
-
+
context "when a source is not given" do
it "should execute 'hg init'" do
provider.expects(:hg).with('init', resource.value(:path))
before do
expects_chdir
end
-
+
context "when given a non-SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
end
-
+
context "when its SHA is not different than the current SHA", :resource => {:revision => '0.6'} do
it "should return the ref" do
provider.revision.should == '0.6'
end
end
-
+
context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do
it "should return the current SHA" do
provider.revision.should == '34e6012c783a'
- end
+ end
end
end
context "when given a SHA as the resource revision" do
before do
provider.expects(:hg).with('parents').returns(fixture(:hg_parents))
end
-
+
context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do
it "should return it" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
provider.revision.should == resource.value(:revision)
end
end
-
+
context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do
it "should return the current SHA" do
provider.expects(:hg).with('tags').returns(fixture(:hg_tags))
end
end
end
-
+
describe "setting the revision property" do
before do
@revision = '6aa99e9b3ab1'
resource.value(:source),
resource.value(:path))
provider.create
- end
+ end
end
resource_without :revision do
it "should just execute 'svn checkout' without a revision" do
resource.value(:source),
resource.value(:path))
provider.create
- end
+ end
end
end
resource_without :source do
provider.revision.should == '3' # From 'Last Changed Rev', not 'Revision'
end
end
-
+
describe "setting the revision property" do
before do
@revision = '30'