From: Junio C Hamano Date: Fri, 20 Mar 2009 21:29:03 +0000 (-0700) Subject: Merge branch 'fc/parseopt-config' X-Git-Tag: v1.6.3-rc0~126 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/17e46ea6fea5273b51b424a8016f9da3412792d4?hp=-c Merge branch 'fc/parseopt-config' * fc/parseopt-config: config: test for --replace-all with one argument and fix documentation. config: set help text for --bool-or-int git config: don't allow --get-color* and variable type git config: don't allow extra arguments for -e or -l. git config: don't allow multiple variable types git config: don't allow multiple config file locations git config: reorganize to use parseopt git config: reorganize get_color* git config: trivial rename in preparation for parseopt git_config(): not having a per-repo config file is not an error --- 17e46ea6fea5273b51b424a8016f9da3412792d4 diff --combined Documentation/git-config.txt index 82ce89eae8,8b94f19b17..7131ee3c66 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@@ -11,7 -11,7 +11,7 @@@ SYNOPSI [verse] 'git config' [] [type] [-z|--null] name [value [value_regex]] 'git config' [] [type] --add name value - 'git config' [] [type] --replace-all name [value [value_regex]] + 'git config' [] [type] --replace-all name value [value_regex] 'git config' [] [type] [-z|--null] --get name [value_regex] 'git config' [] [type] [-z|--null] --get-all name [value_regex] 'git config' [] [type] [-z|--null] --get-regexp name_regex [value_regex] @@@ -131,10 -131,6 +131,10 @@@ See also <> in the config file will cause the value to be multiplied by 1024, 1048576, or 1073741824 prior to output. +--bool-or-int:: + 'git-config' will ensure that the output matches the format of + either --bool or --int, as described above. + -z:: --null:: For all options that output values and/or keys, always diff --combined config.c index 0c8c76f13b,b4aae71bd3..50efd639c4 --- a/config.c +++ b/config.c @@@ -469,6 -469,11 +469,6 @@@ static int git_default_core_config(cons return 0; } - if (!strcmp(var, "core.notesref")) { - notes_ref_name = xstrdup(value); - return 0; - } - if (!strcmp(var, "core.pager")) return git_config_string(&pager_program, var, value); @@@ -565,15 -570,6 +565,15 @@@ static int git_default_branch_config(co return 0; } +static int git_default_mailmap_config(const char *var, const char *value) +{ + if (!strcmp(var, "mailmap.file")) + return git_config_string(&git_mailmap_file, var, value); + + /* Add other config variables here and to Documentation/config.txt. */ + return 0; +} + int git_default_config(const char *var, const char *value, void *dummy) { if (!prefixcmp(var, "core.")) @@@ -588,9 -584,6 +588,9 @@@ if (!prefixcmp(var, "branch.")) return git_default_branch_config(var, value); + if (!prefixcmp(var, "mailmap.")) + return git_default_mailmap_config(var, value); + if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) { pager_use_color = git_config_bool(var,value); return 0; @@@ -644,28 -637,37 +644,37 @@@ int git_config_global(void int git_config(config_fn_t fn, void *data) { - int ret = 0; + int ret = 0, found = 0; char *repo_config = NULL; const char *home = NULL; /* Setting $GIT_CONFIG makes git read _only_ the given config file. */ if (config_exclusive_filename) return git_config_from_file(fn, config_exclusive_filename, data); - if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) + if (git_config_system() && !access(git_etc_gitconfig(), R_OK)) { ret += git_config_from_file(fn, git_etc_gitconfig(), data); + found += 1; + } home = getenv("HOME"); if (git_config_global() && home) { char *user_config = xstrdup(mkpath("%s/.gitconfig", home)); - if (!access(user_config, R_OK)) + if (!access(user_config, R_OK)) { ret += git_config_from_file(fn, user_config, data); + found += 1; + } free(user_config); } repo_config = git_pathdup("config"); - ret += git_config_from_file(fn, repo_config, data); + if (!access(repo_config, R_OK)) { + ret += git_config_from_file(fn, repo_config, data); + found += 1; + } free(repo_config); + if (found == 0) + return -1; return ret; } diff --combined t/t1300-repo-config.sh index 3c06842d99,f0a75380b3..9c81e041b9 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@@ -118,7 -118,14 +118,14 @@@ EO test_expect_success 'multiple unset is correct' 'cmp .git/config expect' - mv .git/config2 .git/config + cp .git/config2 .git/config + + test_expect_success '--replace-all missing value' ' + test_must_fail git config --replace-all beta.haha && + test_cmp .git/config2 .git/config + ' + + rm .git/config2 test_expect_success '--replace-all' \ 'git config --replace-all beta.haha gamma' @@@ -336,10 -343,10 +343,10 @@@ test_expect_success 'get bool variable 'git config --bool emptyvalue.variable > output && cmp output expect' -git config > output 2>&1 - -test_expect_success 'no arguments, but no crash' \ - "test $? = 129 && grep usage output" +test_expect_success 'no arguments, but no crash' ' + test_must_fail git config >output 2>&1 && + grep usage output +' cat > .git/config << EOF [a.b] @@@ -373,7 -380,7 +380,7 @@@ EO test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect' test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \ - 'git config --file non-existing-config -l; test $? != 0' + 'test_must_fail git config --file non-existing-config -l' cat > other-config << EOF [ein]