From db918c02be0811dd56b314a9e95f771a525d116e Mon Sep 17 00:00:00 2001 From: Adam Hess Date: Tue, 7 Apr 2020 15:40:07 -0700 Subject: [PATCH 1/2] each_key returns individual keys not wrapped in an internal array Previously keys where returned in nested arrays i.e. [["user.email"]...] this returns the behavior to just returning keys The behavior changed in #803 likely due to a copy paste mistake. This returns this to the previous behavior --- ext/rugged/rugged_config.c | 2 +- test/config_test.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ext/rugged/rugged_config.c b/ext/rugged/rugged_config.c index 63c00604a..29895630e 100644 --- a/ext/rugged/rugged_config.c +++ b/ext/rugged/rugged_config.c @@ -173,7 +173,7 @@ static int cb_config__each_key(const git_config_entry *entry, void *payload) { int *exception = (int *) payload; - rb_protect(rb_yield, rb_ary_new3(1, rb_str_new_utf8(entry->name)), exception); + rb_protect(rb_yield, rb_str_new_utf8(entry->name), exception); return (*exception != 0) ? GIT_EUSER : GIT_OK; } diff --git a/test/config_test.rb b/test/config_test.rb index 51d71fece..098366d1e 100644 --- a/test/config_test.rb +++ b/test/config_test.rb @@ -43,6 +43,13 @@ def test_snapshot assert_nil snapshot['new.value'] end + def test_each_key_is_a_string + config = @repo.config + config.each_key do |key| + assert key.is_a?(String) + end + end + def test_transaction config = Rugged::Config.new(File.join(@repo.path, 'config')) config['section.name'] = 'value' From cbf05233aae0ce1fe29f269484a1c7a8b64daade Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Thu, 9 Apr 2020 09:30:58 +0200 Subject: [PATCH 2/2] config: add a test for pair types as well --- test/config_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/config_test.rb b/test/config_test.rb index 098366d1e..99ea9b032 100644 --- a/test/config_test.rb +++ b/test/config_test.rb @@ -50,6 +50,14 @@ def test_each_key_is_a_string end end + def test_each_pair_is_pairs + config = @repo.config + config.each_pair do |key, value| + assert key.is_a?(String) + assert value.is_a?(String) + end + end + def test_transaction config = Rugged::Config.new(File.join(@repo.path, 'config')) config['section.name'] = 'value'