Skip to content

Commit 47051ed

Browse files
Preventing Git::Config.git_ssh from overwriting the previously set GIT_SSH env value unless a custom value is set via Git.configure
closes ruby-git#212
1 parent 308281f commit 47051ed

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

lib/git/config.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@ module Git
22

33
class Config
44

5-
attr_writer :binary_path
6-
7-
attr_accessor :git_ssh
5+
attr_writer :binary_path, :git_ssh
86

97
def initialize
108
@binary_path = nil
9+
@git_ssh = nil
1110
end
1211

1312
def binary_path
1413
@binary_path || 'git'
1514
end
1615

16+
def git_ssh
17+
@git_ssh || ENV['GIT_SSH']
18+
end
19+
1720
end
1821

1922
end

tests/units/test_config.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,23 @@ def test_set_config
2929
end
3030

3131
def test_env_config
32+
assert_equal(Git::Base.config.git_ssh, nil)
33+
34+
ENV['GIT_SSH'] = '/env/git/ssh'
35+
36+
assert_equal(Git::Base.config.git_ssh, '/env/git/ssh')
37+
3238
Git.configure do |config|
33-
config.binary_path = "/usr/bin/git"
34-
config.git_ssh = "/path/to/ssh/script"
39+
config.binary_path = '/usr/bin/git'
40+
config.git_ssh = '/path/to/ssh/script'
3541
end
42+
43+
assert_equal(Git::Base.config.git_ssh, '/path/to/ssh/script')
3644

3745
@git.log
3846
ensure
47+
ENV['GIT_SSH'] = nil
48+
3949
Git.configure do |config|
4050
config.binary_path = nil
4151
config.git_ssh = nil

0 commit comments

Comments
 (0)