This repository was archived by the owner on Jun 5, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +77
-48
lines changed
Expand file tree Collapse file tree 6 files changed +77
-48
lines changed Original file line number Diff line number Diff line change 1111# Notes:
1212# None
1313Facter . add ( 'git_exec_path' ) do
14- case Facter . value ( :osfamily )
15- when 'windows'
16- null_path = 'nul'
17- else
18- null_path = '/dev/null'
19- end
20- git_exec_path_cmd = "git --exec-path 2>#{ null_path } "
21- setcode do
22- Facter ::Util ::Resolution . exec ( git_exec_path_cmd )
14+ if Facter . value ( :git_version )
15+ null_path = case Facter . value ( :osfamily )
16+ when 'windows'
17+ 'nul'
18+ else
19+ '/dev/null'
20+ end
21+ git_exec_path_cmd = "git --exec-path 2>#{ null_path } "
22+ setcode do
23+ Facter ::Util ::Resolution . exec ( git_exec_path_cmd )
24+ end
2325 end
2426end
25-
Original file line number Diff line number Diff line change 1111# Notes:
1212# None
1313Facter . add ( 'git_html_path' ) do
14- case Facter . value ( :osfamily )
15- when 'windows'
16- null_path = 'nul'
17- else
18- null_path = '/dev/null'
19- end
20- git_html_path_cmd = "git --html-path 2>#{ null_path } "
21- setcode do
22- Facter ::Util ::Resolution . exec ( git_html_path_cmd )
14+ if Facter . value ( :git_version )
15+ null_path = case Facter . value ( :osfamily )
16+ when 'windows'
17+ 'nul'
18+ else
19+ '/dev/null'
20+ end
21+ git_html_path_cmd = "git --html-path 2>#{ null_path } "
22+ setcode do
23+ Facter ::Util ::Resolution . exec ( git_html_path_cmd )
24+ end
2325 end
2426end
Original file line number Diff line number Diff line change 1212# None
1313Facter . add ( 'git_version' ) do
1414 setcode do
15- if Facter ::Util ::Resolution . which ( 'git' )
16- git_version_cmd = 'git --version 2>&1'
17- git_version_result = Facter ::Util ::Resolution . exec ( git_version_cmd )
18- git_version_result . to_s . lines . first . strip . split ( /version/ ) [ 1 ] . strip
15+ git = Facter ::Util ::Resolution . which ( 'git' )
16+ if git
17+ # On macOS, /usr/bin/git exists by default but is not actually git;
18+ # instead it is a stub to git inside of the active Xcode directory.
19+ # If there isn't one, calling git spawns an unwanted GUI prompt to
20+ # install the Xcode command line tools.
21+ if ( git == '/usr/bin/git' ) && ( Facter . value ( :kernel ) == 'Darwin' )
22+ # check if it is really git
23+ Facter ::Util ::Resolution . exec ( '/usr/bin/xcode-select -p' )
24+ gitmissing = true if $CHILD_STATUS. exitstatus . nonzero?
25+ end
26+ unless gitmissing
27+ git_version_cmd = 'git --version 2>&1'
28+ git_version_result = Facter ::Util ::Resolution . exec ( git_version_cmd )
29+ git_version_result . to_s . lines . first . strip . split ( /version/ ) [ 1 ] . strip
30+ end
1931 end
2032 end
2133end
Original file line number Diff line number Diff line change 1- require " spec_helper"
1+ require ' spec_helper'
22
33describe Facter ::Util ::Fact do
4- before {
4+ before do
55 Facter . clear
6- }
7-
8- describe "git_exec_path" do
6+ end
97
8+ describe 'git_exec_path' do
109 context 'windows' do
1110 it do
1211 Facter . fact ( :osfamily ) . stubs ( :value ) . returns ( 'windows' )
13- Facter ::Util ::Resolution . expects ( :exec ) . with ( "git --exec-path 2>nul" ) . returns ( 'windows_path_change' )
12+ Facter . fact ( :git_version ) . stubs ( :value ) . returns ( '1.7.1' )
13+ Facter ::Util ::Resolution . expects ( :exec ) . with ( 'git --exec-path 2>nul' ) . returns ( 'windows_path_change' )
1414 Facter . fact ( :git_exec_path ) . value . should == 'windows_path_change'
1515 end
1616 end
1717
1818 context 'non-windows' do
1919 it do
2020 Facter . fact ( :osfamily ) . stubs ( :value ) . returns ( 'RedHat' )
21- Facter ::Util ::Resolution . expects ( :exec ) . with ( "git --exec-path 2>/dev/null" ) . returns ( '/usr/libexec/git-core' )
21+ Facter . fact ( :git_version ) . stubs ( :value ) . returns ( '1.7.1' )
22+ Facter ::Util ::Resolution . expects ( :exec ) . with ( 'git --exec-path 2>/dev/null' ) . returns ( '/usr/libexec/git-core' )
2223 Facter . fact ( :git_exec_path ) . value . should == '/usr/libexec/git-core'
2324 end
2425 end
2526
27+ context 'no git present' do
28+ it do
29+ Facter . fact ( :git_version ) . stubs ( :value ) . returns ( nil )
30+ Facter . fact ( :git_exec_path ) . value . should be_nil
31+ end
32+ end
2633 end
27- end
34+ end
Original file line number Diff line number Diff line change 1- require " spec_helper"
1+ require ' spec_helper'
22
33describe Facter ::Util ::Fact do
4- before {
4+ before do
55 Facter . clear
6- }
7-
8- describe "git_html_path" do
6+ end
97
8+ describe 'git_html_path' do
109 context 'windows' do
1110 it do
1211 Facter . fact ( :osfamily ) . stubs ( :value ) . returns ( 'windows' )
13- Facter ::Util ::Resolution . expects ( :exec ) . with ( "git --html-path 2>nul" ) . returns ( 'windows_path_change' )
12+ Facter . fact ( :git_version ) . stubs ( :value ) . returns ( '1.7.1' )
13+ Facter ::Util ::Resolution . expects ( :exec ) . with ( 'git --html-path 2>nul' ) . returns ( 'windows_path_change' )
1414 Facter . fact ( :git_html_path ) . value . should == 'windows_path_change'
1515 end
1616 end
1717
1818 context 'non-windows' do
1919 it do
2020 Facter . fact ( :osfamily ) . stubs ( :value ) . returns ( 'RedHat' )
21- Facter ::Util ::Resolution . expects ( :exec ) . with ( "git --html-path 2>/dev/null" ) . returns ( '/usr/share/doc/git-1.7.1' )
21+ Facter . fact ( :git_version ) . stubs ( :value ) . returns ( '1.7.1' )
22+ Facter ::Util ::Resolution . expects ( :exec ) . with ( 'git --html-path 2>/dev/null' ) . returns ( '/usr/share/doc/git-1.7.1' )
2223 Facter . fact ( :git_html_path ) . value . should == '/usr/share/doc/git-1.7.1'
2324 end
2425 end
2526
27+ context 'no git present' do
28+ it do
29+ Facter . fact ( :git_version ) . stubs ( :value ) . returns ( nil )
30+ Facter . fact ( :git_html_path ) . value . should be_nil
31+ end
32+ end
2633 end
27- end
34+ end
Original file line number Diff line number Diff line change 1- require " spec_helper"
1+ require ' spec_helper'
22
33describe Facter ::Util ::Fact do
4- before {
4+ before do
55 Facter . clear
6- }
6+ end
77
8- describe " git_version" do
8+ describe ' git_version' do
99 context 'vanilla git' do
1010 it do
1111 git_version_output = 'git version 2.1.2'
12- Facter ::Util ::Resolution . expects ( :exec ) . with ( " git --version 2>&1" ) . returns ( git_version_output )
13- Facter . value ( :git_version ) . should == " 2.1.2"
12+ Facter ::Util ::Resolution . expects ( :exec ) . with ( ' git --version 2>&1' ) . returns ( git_version_output )
13+ Facter . value ( :git_version ) . should == ' 2.1.2'
1414 end
1515 end
1616
2020git version 2.1.2
2121hub version 1.12.2
2222 EOS
23- Facter ::Util ::Resolution . expects ( :exec ) . with ( " git --version 2>&1" ) . returns ( git_version_output )
24- Facter . value ( :git_version ) . should == " 2.1.2"
23+ Facter ::Util ::Resolution . expects ( :exec ) . with ( ' git --version 2>&1' ) . returns ( git_version_output )
24+ Facter . value ( :git_version ) . should == ' 2.1.2'
2525 end
2626 end
2727
2828 context 'no git present' do
2929 it do
30- Facter ::Util ::Resolution . expects ( :which ) . with ( " git" ) . returns ( false )
30+ Facter ::Util ::Resolution . expects ( :which ) . with ( ' git' ) . returns ( false )
3131 Facter . value ( :git_version ) . should be_nil
3232 end
3333 end
You can’t perform that action at this time.
0 commit comments