Skip to content

Fix Git module config method #399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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>
  • Loading branch information
Michal Papis committed Mar 25, 2019
commit 5b12f828c7d0ccdd9a2b6b7d1e9c98eca2d2593d
4 changes: 2 additions & 2 deletions lib/git/lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
40 changes: 40 additions & 0 deletions tests/units/test_config_module.rb
Original file line number Diff line number Diff line change
@@ -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