Skip to content

Commit 5b12f82

Browse files
author
Michal Papis
committed
Fix Git module config method
The Git module config method when used via `include Git` does not work as the `lambda` requires parameters to be present and the second part of condition in Git::Lib::config_get calls the lambda without any params, switching to `Proc.new` fixes the problem. Signed-off-by: Michal Papis <michal.papis@toptal.com>
1 parent 9bd4407 commit 5b12f82

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lib/git/lib.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def config_remote(name)
441441
end
442442

443443
def config_get(name)
444-
do_get = lambda do |path|
444+
do_get = Proc.new do |path|
445445
command('config', ['--get', name])
446446
end
447447

@@ -457,7 +457,7 @@ def global_config_get(name)
457457
end
458458

459459
def config_list
460-
build_list = lambda do |path|
460+
build_list = Proc.new do |path|
461461
parse_config_list command_lines('config', ['--list'])
462462
end
463463

tests/units/test_config_module.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env ruby
2+
3+
require File.dirname(__FILE__) + '/../test_helper'
4+
5+
class TestConfigModule < Test::Unit::TestCase
6+
def setup
7+
set_file_paths
8+
git_class = Class.new do
9+
include Git
10+
end
11+
@git = git_class.new
12+
@old_dir = Dir.pwd
13+
Dir.chdir(@wdir)
14+
end
15+
16+
teardown
17+
def test_teardown
18+
Dir.chdir(@old_dir)
19+
end
20+
21+
def test_config
22+
c = @git.config
23+
assert_equal('Scott Chacon', c['user.name'])
24+
assert_equal('false', c['core.bare'])
25+
end
26+
27+
def test_read_config
28+
assert_equal('Scott Chacon', @git.config('user.name'))
29+
assert_equal('false', @git.config('core.bare'))
30+
end
31+
32+
def test_set_config
33+
in_temp_dir do |path|
34+
g = Git.clone(@wbare, 'bare')
35+
assert_not_equal('bully', g.config('user.name'))
36+
g.config('user.name', 'bully')
37+
assert_equal('bully', g.config('user.name'))
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)