diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-09-03 15:53:06 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-09-03 15:53:07 -0700 |
commit | 3e06f5ff3870279f3bf2f97d4a4256032575055e (patch) | |
tree | 28b499c52dda30a471536facf32a6a542c45a8eb | |
parent | 16d26b168b371b2f4f86b1adb61470c6b08b27b9 (diff) | |
parent | 9409c7a5b33d6a4d68f58ccb1034fa50c92cac68 (diff) | |
download | git-3e06f5ff3870279f3bf2f97d4a4256032575055e.tar.gz |
Merge branch 'jc/maint-config-exit-status'
The exit status code from "git config" was way overspecified while
being incorrect. Update the implementation to give the documented
status for a case that was documented, and introduce a new code for
"all other errors".
* jc/maint-config-exit-status:
config: "git config baa" should exit with status 1
-rw-r--r-- | Documentation/git-config.txt | 8 | ||||
-rw-r--r-- | builtin/config.c | 8 | ||||
-rw-r--r-- | cache.h | 1 |
3 files changed, 11 insertions, 6 deletions
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 490868eb23..eaea079165 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -54,16 +54,16 @@ configuration file by default, and options '--system', '--global', '--file <filename>' can be used to tell the command to write to that location (you can say '--local' but that is the default). -This command will fail (with exit code ret) if: +This command will fail with non-zero status upon error. Some exit +codes are: . The config file is invalid (ret=3), . can not write to the config file (ret=4), . no section or name was provided (ret=2), . the section or key is invalid (ret=1), . you try to unset an option which does not exist (ret=5), -. you try to unset/set an option for which multiple lines match (ret=5), -. you try to use an invalid regexp (ret=6), or -. you use '--global' option without $HOME being properly set (ret=128). +. you try to unset/set an option for which multiple lines match (ret=5), or +. you try to use an invalid regexp (ret=6). On success, the command returns the exit code 0. diff --git a/builtin/config.c b/builtin/config.c index 8cd08da991..ada6e12114 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -160,7 +160,7 @@ static int show_config(const char *key_, const char *value_, void *cb) static int get_value(const char *key_, const char *regex_) { - int ret = -1; + int ret = CONFIG_GENERIC_ERROR; char *global = NULL, *xdg = NULL, *repo_config = NULL; const char *system_wide = NULL, *local; struct config_include_data inc = CONFIG_INCLUDE_INIT; @@ -196,11 +196,14 @@ static int get_value(const char *key_, const char *regex_) if (regcomp(key_regexp, key, REG_EXTENDED)) { fprintf(stderr, "Invalid key pattern: %s\n", key_); free(key); + ret = CONFIG_INVALID_PATTERN; goto free_strings; } } else { - if (git_config_parse_key(key_, &key, NULL)) + if (git_config_parse_key(key_, &key, NULL)) { + ret = CONFIG_INVALID_KEY; goto free_strings; + } } if (regex_) { @@ -212,6 +215,7 @@ static int get_value(const char *key_, const char *regex_) regexp = (regex_t*)xmalloc(sizeof(regex_t)); if (regcomp(regexp, regex_, REG_EXTENDED)) { fprintf(stderr, "Invalid pattern: %s\n", regex_); + ret = CONFIG_INVALID_PATTERN; goto free_strings; } } @@ -1110,6 +1110,7 @@ extern int update_server_info(int); #define CONFIG_NO_WRITE 4 #define CONFIG_NOTHING_SET 5 #define CONFIG_INVALID_PATTERN 6 +#define CONFIG_GENERIC_ERROR 7 typedef int (*config_fn_t)(const char *, const char *, void *); extern int git_default_config(const char *, const char *, void *); |