From 5b12f828c7d0ccdd9a2b6b7d1e9c98eca2d2593d Mon Sep 17 00:00:00 2001 From: Michal Papis Date: Mon, 21 Jan 2019 14:28:32 +0100 Subject: [PATCH] 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 --- lib/git/lib.rb | 4 ++-- tests/units/test_config_module.rb | 40 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 tests/units/test_config_module.rb diff --git a/lib/git/lib.rb b/lib/git/lib.rb index a698cf3e..69d9a086 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -441,7 +441,7 @@ def config_remote(name) end def config_get(name) - do_get = lambda do |path| + do_get = Proc.new do |path| command('config', ['--get', name]) end @@ -457,7 +457,7 @@ def global_config_get(name) end def config_list - build_list = lambda do |path| + build_list = Proc.new do |path| parse_config_list command_lines('config', ['--list']) end diff --git a/tests/units/test_config_module.rb b/tests/units/test_config_module.rb new file mode 100644 index 00000000..b19b9625 --- /dev/null +++ b/tests/units/test_config_module.rb @@ -0,0 +1,40 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../test_helper' + +class TestConfigModule < Test::Unit::TestCase + def setup + set_file_paths + git_class = Class.new do + include Git + end + @git = git_class.new + @old_dir = Dir.pwd + Dir.chdir(@wdir) + end + + teardown + def test_teardown + Dir.chdir(@old_dir) + end + + def test_config + c = @git.config + assert_equal('Scott Chacon', c['user.name']) + assert_equal('false', c['core.bare']) + end + + def test_read_config + assert_equal('Scott Chacon', @git.config('user.name')) + assert_equal('false', @git.config('core.bare')) + end + + def test_set_config + in_temp_dir do |path| + g = Git.clone(@wbare, 'bare') + assert_not_equal('bully', g.config('user.name')) + g.config('user.name', 'bully') + assert_equal('bully', g.config('user.name')) + end + end +end