@@ -209,7 +209,7 @@ def branch_a_list(include_branch = nil?)
209
209
end
210
210
end
211
211
212
- context 'when when converting repo type' do
212
+ context 'when converting repo type' do
213
213
context 'when with working copy to bare' do
214
214
it 'converts the repo' do
215
215
resource [ :ensure ] = :bare
@@ -276,54 +276,78 @@ def branch_a_list(include_branch = nil?)
276
276
end
277
277
end
278
278
279
- context 'when when destroying' do
279
+ context 'when destroying' do
280
280
it 'removes the directory' do
281
281
expects_rm_rf
282
282
provider . destroy
283
283
end
284
284
end
285
285
286
- context 'when when checking the revision property' do
286
+ context 'when checking the revision property' do
287
287
before ( :each ) do
288
288
expects_chdir ( '/tmp/test' )
289
- resource [ :revision ] = 'currentsha'
290
289
resource [ :source ] = 'http://example.com'
291
290
provider . stubs ( :git ) . with ( 'config' , 'remote.origin.url' ) . returns ( '' )
292
291
provider . stubs ( :git ) . with ( 'fetch' , 'origin' ) # FIXME
293
292
provider . stubs ( :git ) . with ( 'fetch' , '--tags' , 'origin' )
294
293
provider . stubs ( :git ) . with ( 'rev-parse' , 'HEAD' ) . returns ( 'currentsha' )
295
- provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list ( resource . value ( :revision ) ) )
296
294
provider . stubs ( :git ) . with ( 'tag' , '-l' ) . returns ( 'Hello' )
297
295
end
298
296
299
- context 'when when its SHA is not different than the current SHA' do
297
+ context 'when its a SHA and is not different than the current SHA' do
298
+ it 'returns the current SHA' do
299
+ resource [ :revision ] = 'currentsha'
300
+ provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list )
301
+ provider . expects ( :git ) . with ( 'rev-parse' , '--revs-only' , resource . value ( :revision ) ) . never
302
+ provider . expects ( :update_references ) . never
303
+ expect ( provider . revision ) . to eq ( resource . value ( :revision ) )
304
+ end
305
+ end
306
+
307
+ context 'when its a SHA and is different than the current SHA' do
308
+ it 'returns the current SHA' do
309
+ resource [ :revision ] = 'othersha'
310
+ provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list )
311
+ provider . expects ( :git ) . with ( 'rev-parse' , '--revs-only' , resource . value ( :revision ) ) . returns ( 'othersha' )
312
+ provider . expects ( :update_references )
313
+ expect ( provider . revision ) . to eq ( 'currentsha' )
314
+ end
315
+ end
316
+
317
+ context 'when its a local branch and is not different than the current SHA' do
300
318
it 'returns the ref' do
319
+ resource [ :revision ] = 'localbranch'
320
+ provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list ( 'localbranch' ) )
301
321
provider . expects ( :git ) . with ( 'rev-parse' , resource . value ( :revision ) ) . returns ( 'currentsha' )
302
322
provider . expects ( :update_references )
303
323
expect ( provider . revision ) . to eq ( resource . value ( :revision ) )
304
324
end
305
325
end
306
326
307
- context 'when when its SHA is different than the current SHA' do
327
+ context 'when its a local branch and is different than the current SHA' do
308
328
it 'returns the current SHA' do
329
+ resource [ :revision ] = 'localbranch'
330
+ provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list ( 'localbranch' ) )
309
331
provider . expects ( :git ) . with ( 'rev-parse' , resource . value ( :revision ) ) . returns ( 'othersha' )
310
332
provider . expects ( :update_references )
311
- expect ( provider . revision ) . to eq ( resource . value ( :revision ) )
333
+ expect ( provider . revision ) . to eq ( 'currentsha' )
312
334
end
313
335
end
314
336
315
- context 'when when its a ref to a remote head' do
316
- it 'returns the revision' do
337
+ context 'when its a ref to a remote head' do
338
+ it 'returns the ref' do
339
+ resource [ :revision ] = 'remotebranch'
317
340
provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( " remotes/origin/#{ resource . value ( :revision ) } " )
318
- provider . expects ( :git ) . with ( 'rev-parse' , "origin/#{ resource . value ( :revision ) } " ) . returns ( 'newsha ' )
341
+ provider . expects ( :git ) . with ( 'rev-parse' , "origin/#{ resource . value ( :revision ) } " ) . returns ( 'currentsha ' )
319
342
provider . expects ( :update_references )
320
343
expect ( provider . revision ) . to eq ( resource . value ( :revision ) )
321
344
end
322
345
end
323
346
324
- context 'when when its a ref to non existant remote head' do
347
+ context 'when its a ref to non existant remote head' do
325
348
it 'fails' do
326
- provider . expects ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list )
349
+ resource [ :revision ] = 'remotebranch'
350
+ provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list )
327
351
provider . expects ( :git ) . with ( 'rev-parse' , '--revs-only' , resource . value ( :revision ) ) . returns ( '' )
328
352
provider . expects ( :update_references )
329
353
expect { provider . revision } . to raise_error ( RuntimeError , %r{not a local or remote ref$} )
@@ -332,7 +356,10 @@ def branch_a_list(include_branch = nil?)
332
356
333
357
context "when there's no source" do
334
358
it 'returns the revision' do
359
+ resource [ :revision ] = 'localbranch'
335
360
resource . delete ( :source )
361
+ provider . stubs ( :git ) . with ( 'branch' , '-a' ) . returns ( branch_a_list ( 'localbranch' ) )
362
+ provider . expects ( :update_references ) . never
336
363
provider . expects ( :git ) . with ( 'status' )
337
364
provider . expects ( :git ) . with ( 'rev-parse' , resource . value ( :revision ) ) . returns ( 'currentsha' )
338
365
expect ( provider . revision ) . to eq ( resource . value ( :revision ) )
0 commit comments