Using rev-parse to determine branch name of HEAD for on_branch? method
authorMike Gerwitz <gerwitzm@lovullo.com>
Mon, 2 Dec 2013 16:38:56 +0000 (11:38 -0500)
committerMike Gerwitz <gerwitzm@lovullo.com>
Mon, 2 Dec 2013 17:24:04 +0000 (12:24 -0500)
lib/puppet/provider/vcsrepo/git.rb
spec/unit/puppet/provider/vcsrepo/git_spec.rb

index 6bc1c3d..17275c4 100644 (file)
@@ -39,7 +39,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
 
   def latest
     branch = on_branch?
-    if branch == '(no branch)'
+    if branch == ''
       return get_revision('HEAD')
     else
       return get_revision("#{@resource.value(:remote)}/%s" % branch)
@@ -253,7 +253,7 @@ Puppet::Type.type(:vcsrepo).provide(:git, :parent => Puppet::Provider::Vcsrepo)
   end
 
   def on_branch?
-    at_path { git_with_identity('branch', '-a') }.split(/\n/).grep(/\*/).first.to_s.gsub('*', '').strip
+    at_path { git_with_identity('rev-parse', '--abbrev-ref', 'HEAD') }
   end
 
   def tags
index 15fee53..f3d9dd3 100644 (file)
@@ -323,19 +323,19 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do
     end
     context 'on master' do
       it do
-        provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a))
+        provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_a))
         provider.latest.should == 'master'
       end
     end
     context 'no branch' do
       it do
-        provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_none))
+        provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_none))
         provider.latest.should == 'master'
       end
     end
     context 'feature/bar' do
       it do
-        provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_feature_bar))
+        provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_feature_bar))
         provider.latest.should == 'master'
       end
     end