From 5bf6529aaa3fa829328ae00ddf7aa851935443b5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Jun 2011 11:51:36 -0400 Subject: fix "git -c" parsing of values with equals signs If you do something like: git -c core.foo="value with = in it" ... we would split your option on "=" into three fields and throw away the third one. With this patch we correctly take everything after the first "=" as the value (keys cannot have an equals sign in them, so the parsing is unambiguous). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 't') diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 3db56267e..ca5058e0d 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -904,4 +904,10 @@ test_expect_success 'git -c works with aliases of builtins' ' test_cmp expect actual ' +test_expect_success 'git -c does not split values on equals' ' + echo "value with = in it" >expect && + git -c core.foo="value with = in it" config core.foo >actual && + test_cmp expect actual +' + test_done -- cgit v1.2.1 From 1c2c9bee1bad9a4133a934d04c32b033cc16c8aa Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Jun 2011 11:52:32 -0400 Subject: config: die on error in command-line config The error handling for git_config is somewhat confusing. We collect errors from running git_config_from_file on the various config files and carefully pass them back up. But the two odd things are: 1. We actually die on most errors in git_config_from_file. In fact, the only error we actually pass back up is if fopen() fails on the file. 2. Most callers of git_config do not check the error return at all, but will continue if git_config reports an error. When the code for "git -c core.foo=bar" was added, it dutifully passed errors up the call stack, only for them to be eventually ignored. This makes it inconsistent with the file-parsing code, which will die when it sees malformed config. And it's somewhat unsafe, because it means an error in parsing a typo like: git -c clean.requireforce=ture clean will continue the command, ignoring the config the user tried to give. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 't') diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index ca5058e0d..584e956ac 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -910,4 +910,12 @@ test_expect_success 'git -c does not split values on equals' ' test_cmp expect actual ' +test_expect_success 'git -c dies on bogus config' ' + test_must_fail git -c core.bare=foo rev-parse +' + +test_expect_success 'git -c complains about empty key' ' + test_must_fail git -c "=foo" rev-parse +' + test_done -- cgit v1.2.1 From c5d6350bdc8d0d8bd4bd1aa0273313e71cd548f6 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Thu, 9 Jun 2011 11:52:43 -0400 Subject: config: avoid segfault when parsing command-line config We already check for an empty key on the left side of an equals, but we would segfault if there was no content at all. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t1300-repo-config.sh | 4 ++++ 1 file changed, 4 insertions(+) (limited to 't') diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 584e956ac..3e140c18f 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -918,4 +918,8 @@ test_expect_success 'git -c complains about empty key' ' test_must_fail git -c "=foo" rev-parse ' +test_expect_success 'git -c complains about empty key and value' ' + test_must_fail git -c "" rev-parse +' + test_done -- cgit v1.2.1