From: Junio C Hamano Date: Wed, 1 Jun 2011 21:05:22 +0000 (-0700) Subject: Merge branch 'jk/maint-config-alias-fix' into maint X-Git-Tag: v1.7.5.4~1 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=1c6e3514d093377fec5e30aa02a119187cf743f2;p=git.git Merge branch 'jk/maint-config-alias-fix' into maint * jk/maint-config-alias-fix: handle_options(): do not miscount how many arguments were used config: always parse GIT_CONFIG_PARAMETERS during git_config git_config: don't peek at global config_parameters config: make environment parsing routines static --- 1c6e3514d093377fec5e30aa02a119187cf743f2 diff --cc config.c index d06fb19d5,8220c0cbf..61de4d6a1 --- a/config.c +++ b/config.c @@@ -839,22 -801,11 +827,6 @@@ int git_config_system(void return !git_env_bool("GIT_CONFIG_NOSYSTEM", 0); } - int git_config_from_parameters(config_fn_t fn, void *data) -int git_config_global(void) --{ - static int loaded_environment; - const struct config_item *ct; - - if (!loaded_environment) { - if (git_config_parse_environment() < 0) - return -1; - loaded_environment = 1; - } - for (ct = config_parameters; ct; ct = ct->next) - if (fn(ct->name, ct->value, data) < 0) - return -1; - return 0; - return !git_env_bool("GIT_CONFIG_NOGLOBAL", 0); --} -- int git_config_early(config_fn_t fn, void *data, const char *repo_config) { int ret = 0, found = 0; @@@ -884,11 -835,20 +856,18 @@@ found += 1; } - ret += git_config_from_parameters(fn, data); - if (config_parameters) - found += 1; + switch (git_config_from_parameters(fn, data)) { + case -1: /* error */ + ret--; + break; + case 0: /* found nothing */ + break; + default: /* found at least one item */ + found++; + break; + } - if (found == 0) - return -1; - return ret; + return ret == 0 ? found : ret; } int git_config(config_fn_t fn, void *data) diff --cc t/t1300-repo-config.sh index 53fb8228c,de2a014d8..3db56267e --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@@ -876,25 -847,18 +876,32 @@@ test_expect_success 'check split_cmdlin " test_expect_success 'git -c "key=value" support' ' - test "z$(git -c name=value config name)" = zvalue && test "z$(git -c core.name=value config core.name)" = zvalue && - test "z$(git -c CamelCase=value config camelcase)" = zvalue && - test "z$(git -c flag config --bool flag)" = ztrue && - test_must_fail git -c core.name=value config name + test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue && + test "z$(git -c foo.flag config --bool foo.flag)" = ztrue && + test_must_fail git -c name=value config core.name +' + +test_expect_success 'key sanity-checking' ' + test_must_fail git config foo=bar && + test_must_fail git config foo=.bar && + test_must_fail git config foo.ba=r && + test_must_fail git config foo.1bar && + test_must_fail git config foo."ba + z".bar && + test_must_fail git config . false && + test_must_fail git config .foo false && + test_must_fail git config foo. false && + test_must_fail git config .foo. false && + git config foo.bar true && + git config foo."ba =z".bar false ' + test_expect_success 'git -c works with aliases of builtins' ' + git config alias.checkconfig "-c foo.check=bar config foo.check" && + echo bar >expect && + git checkconfig >actual && + test_cmp expect actual + ' + test_done