This repository was archived by the owner on Jun 5, 2020. It is now read-only.
File tree 6 files changed +77
-48
lines changed
6 files changed +77
-48
lines changed Original file line number Diff line number Diff line change 11
11
# Notes:
12
12
# None
13
13
Facter . 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
23
25
end
24
26
end
25
-
Original file line number Diff line number Diff line change 11
11
# Notes:
12
12
# None
13
13
Facter . 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
23
25
end
24
26
end
Original file line number Diff line number Diff line change 12
12
# None
13
13
Facter . add ( 'git_version' ) do
14
14
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
19
31
end
20
32
end
21
33
end
Original file line number Diff line number Diff line change 1
- require " spec_helper"
1
+ require ' spec_helper'
2
2
3
3
describe Facter ::Util ::Fact do
4
- before {
4
+ before do
5
5
Facter . clear
6
- }
7
-
8
- describe "git_exec_path" do
6
+ end
9
7
8
+ describe 'git_exec_path' do
10
9
context 'windows' do
11
10
it do
12
11
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' )
14
14
Facter . fact ( :git_exec_path ) . value . should == 'windows_path_change'
15
15
end
16
16
end
17
17
18
18
context 'non-windows' do
19
19
it do
20
20
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' )
22
23
Facter . fact ( :git_exec_path ) . value . should == '/usr/libexec/git-core'
23
24
end
24
25
end
25
26
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
26
33
end
27
- end
34
+ end
Original file line number Diff line number Diff line change 1
- require " spec_helper"
1
+ require ' spec_helper'
2
2
3
3
describe Facter ::Util ::Fact do
4
- before {
4
+ before do
5
5
Facter . clear
6
- }
7
-
8
- describe "git_html_path" do
6
+ end
9
7
8
+ describe 'git_html_path' do
10
9
context 'windows' do
11
10
it do
12
11
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' )
14
14
Facter . fact ( :git_html_path ) . value . should == 'windows_path_change'
15
15
end
16
16
end
17
17
18
18
context 'non-windows' do
19
19
it do
20
20
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' )
22
23
Facter . fact ( :git_html_path ) . value . should == '/usr/share/doc/git-1.7.1'
23
24
end
24
25
end
25
26
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
26
33
end
27
- end
34
+ end
Original file line number Diff line number Diff line change 1
- require " spec_helper"
1
+ require ' spec_helper'
2
2
3
3
describe Facter ::Util ::Fact do
4
- before {
4
+ before do
5
5
Facter . clear
6
- }
6
+ end
7
7
8
- describe " git_version" do
8
+ describe ' git_version' do
9
9
context 'vanilla git' do
10
10
it do
11
11
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'
14
14
end
15
15
end
16
16
20
20
git version 2.1.2
21
21
hub version 1.12.2
22
22
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'
25
25
end
26
26
end
27
27
28
28
context 'no git present' do
29
29
it do
30
- Facter ::Util ::Resolution . expects ( :which ) . with ( " git" ) . returns ( false )
30
+ Facter ::Util ::Resolution . expects ( :which ) . with ( ' git' ) . returns ( false )
31
31
Facter . value ( :git_version ) . should be_nil
32
32
end
33
33
end
You can’t perform that action at this time.
0 commit comments