Skip to content

Commit 181ace3

Browse files
authored
Fix Git module config method (#399)
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 a1202eb commit 181ace3

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
@@ -488,7 +488,7 @@ def config_remote(name)
488488
end
489489

490490
def config_get(name)
491-
do_get = lambda do |path|
491+
do_get = Proc.new do |path|
492492
command('config', '--get', name)
493493
end
494494

@@ -504,7 +504,7 @@ def global_config_get(name)
504504
end
505505

506506
def config_list
507-
build_list = lambda do |path|
507+
build_list = Proc.new do |path|
508508
parse_config_list command_lines('config', '--list')
509509
end
510510

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)