3 describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do
6 resource_with :source do
7 resource_with :ensure => :present do
8 context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do
9 it "should execute 'git clone' and 'git checkout -b'" do
10 provider.expects('git').with('clone', resource.value(:source), resource.value(:path))
12 provider.expects(:remote_revision_branch?).returns(true)
13 provider.expects(:git).with('checkout', '-b', resource.value(:revision), '--track', "origin/#{resource.value(:revision)}")
14 provider.expects(:update_submodules)
18 context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do
19 it "should execute 'git clone' and 'git reset --hard'" do
20 provider.expects('git').with('clone', resource.value(:source), resource.value(:path))
22 provider.expects(:remote_revision_branch?).returns(false)
23 provider.expects('git').with('reset', '--hard', resource.value(:revision))
24 provider.expects(:update_submodules)
28 resource_without :revision do
29 it "should execute 'git clone' and submodule commands" do
30 provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
31 provider.expects(:update_submodules)
37 resource_with :ensure => :bare do
38 resource_with :revision do
39 it "should just execute 'git clone --bare'" do
40 provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
45 resource_without :revision do
46 it "should just execute 'git clone --bare'" do
47 provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
54 context "when a source is not given" do
55 resource_with :ensure => :present do
56 context "when the path does not exist" do
57 it "should execute 'git init'" do
60 expects_directory?(false)
61 provider.expects(:bare_exists?).returns(false)
62 provider.expects(:git).with('init')
67 context "when the path is a bare repository" do
68 it "should convert it to a working copy" do
69 provider.expects(:bare_exists?).returns(true)
70 provider.expects(:convert_bare_to_working_copy)
75 context "when the path is not a repository" do
76 it "should raise an exception" do
77 expects_directory?(true)
78 provider.expects(:bare_exists?).returns(false)
79 proc { provider.create }.should raise_error(Puppet::Error)
84 resource_with :ensure => :bare do
85 context "when the path does not exist" do
86 it "should execute 'git init --bare'" do
89 expects_directory?(false)
90 provider.expects(:working_copy_exists?).returns(false)
91 provider.expects(:git).with('init', '--bare')
96 context "when the path is a working copy repository" do
97 it "should convert it to a bare repository" do
98 provider.expects(:working_copy_exists?).returns(true)
99 provider.expects(:convert_working_copy_to_bare)
104 context "when the path is not a repository" do
105 it "should raise an exception" do
106 expects_directory?(true)
107 provider.expects(:working_copy_exists?).returns(false)
108 proc { provider.create }.should raise_error(Puppet::Error)
116 context 'destroying' do
117 it "it should remove the directory" do
123 context "checking the revision property" do
124 resource_with :revision do
127 provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha')
130 context "when its SHA is not different than the current SHA" do
131 it "should return the ref" do
132 provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
133 provider.revision.should == resource.value(:revision)
137 context "when its SHA is different than the current SHA" do
138 it "should return the current SHA" do
139 provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
140 provider.revision.should == 'currentsha'
146 context "setting the revision property" do
149 provider.expects(:git).with('fetch', 'origin')
151 context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do
152 it "should use 'git fetch' and 'git reset'" do
153 provider.expects(:local_revision_branch?).returns(true)
154 provider.expects(:git).with('checkout', resource.value(:revision))
155 provider.expects(:git).with('pull', 'origin')
156 provider.expects(:update_submodules)
157 provider.revision = resource.value(:revision)
160 context "when it's a remote branch", :resource => {:revision => 'only/remote'} do
161 it "should use 'git fetch' and 'git reset'" do
162 provider.expects(:local_revision_branch?).returns(false)
163 provider.expects(:remote_revision_branch?).returns(true)
164 provider.expects(:git).with('checkout',
165 '-b', resource.value(:revision),
166 '--track', "origin/#{resource.value(:revision)}")
167 provider.expects(:update_submodules)
168 provider.revision = resource.value(:revision)
171 context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do
172 it "should use 'git fetch' and 'git reset'" do
173 provider.expects(:local_revision_branch?).returns(false)
174 provider.expects(:remote_revision_branch?).returns(false)
175 provider.expects(:git).with('reset', '--hard', resource.value(:revision))
176 provider.expects(:git).with('submodule', 'init')
177 provider.expects(:git).with('submodule', 'update')
178 provider.revision = resource.value(:revision)
183 context "updating references" do
184 it "should use 'git fetch --tags'" do
186 provider.expects(:git).with('fetch', '--tags', 'origin')
187 provider.update_references
191 context "checking if revision" do
194 provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
196 context "is a local branch" do
197 context "when it's listed in 'git branch -a'", :resource => {:revision => 'feature/foo'} do
198 it "should return true" do
199 provider.should be_local_branch_revision
202 context "when it's not listed in 'git branch -a'" , :resource => {:revision => 'feature/notexist'}do
203 it "should return false" do
204 provider.should_not be_local_branch_revision
208 context "is a remote branch" do
209 context "when it's listed in 'git branch -a' with an 'origin/' prefix", :resource => {:revision => 'only/remote'} do
210 it "should return true" do
211 provider.should be_remote_branch_revision
214 context "when it's not listed in 'git branch -a' with an 'origin/' prefix" , :resource => {:revision => 'only/local'}do
215 it "should return false" do
216 provider.should_not be_remote_branch_revision