config: "git config baa" should exit with status 1
We instead failed with an undocumented exit status 255. Also define a "catch-all" status and document it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 29, 2012 at 13:43 UTC
9409c7a5b33d6a4d68f58ccb1034fa50c92cac68
3 files changed
+11
-6
Documentation/git-config.txt
+4
-4
@@ -54,16 +54,16 @@ configuration file by default, and options '--system', '--global',
54
'--file <filename>' can be used to tell the command to write to
55
that location (you can say '--local' but that is the default).
56
57
-This command will fail (with exit code ret) if:
57
+This command will fail with non-zero status upon error. Some exit
58
+codes are:
59
60
. The config file is invalid (ret=3),
61
. can not write to the config file (ret=4),
62
. no section or name was provided (ret=2),
63
. the section or key is invalid (ret=1),
64
. you try to unset an option which does not exist (ret=5),
64
-. you try to unset/set an option for which multiple lines match (ret=5),
65
-. you try to use an invalid regexp (ret=6), or
66
-. you use '--global' option without $HOME being properly set (ret=128).
65
+. you try to unset/set an option for which multiple lines match (ret=5), or
66
+. you try to use an invalid regexp (ret=6).
67
68
On success, the command returns the exit code 0.
69
builtin/config.c
+6
-2
@@ -160,7 +160,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
160
161
static int get_value(const char *key_, const char *regex_)
162
{
163
- int ret = -1;
163
+ int ret = CONFIG_GENERIC_ERROR;
164
char *global = NULL, *repo_config = NULL;
165
const char *system_wide = NULL, *local;
166
struct config_include_data inc = CONFIG_INCLUDE_INIT;
@@ -198,11 +198,14 @@ static int get_value(const char *key_, const char *regex_)
198
if (regcomp(key_regexp, key, REG_EXTENDED)) {
199
fprintf(stderr, "Invalid key pattern: %s\n", key_);
200
free(key);
201
+ ret = CONFIG_INVALID_PATTERN;
202
goto free_strings;
203
}
204
} else {
204
- if (git_config_parse_key(key_, &key, NULL))
205
+ if (git_config_parse_key(key_, &key, NULL)) {
206
+ ret = CONFIG_INVALID_KEY;
207
goto free_strings;
208
+ }
209
}
210
211
if (regex_) {
@@ -214,6 +217,7 @@ static int get_value(const char *key_, const char *regex_)
217
regexp = (regex_t*)xmalloc(sizeof(regex_t));
218
if (regcomp(regexp, regex_, REG_EXTENDED)) {
219
fprintf(stderr, "Invalid pattern: %s\n", regex_);
220
+ ret = CONFIG_INVALID_PATTERN;
221
goto free_strings;
222
}
223
}
cache.h
+1
@@ -1141,6 +1141,7 @@ extern int update_server_info(int);
1141
#define CONFIG_NO_WRITE 4
1142
#define CONFIG_NOTHING_SET 5
1143
#define CONFIG_INVALID_PATTERN 6
1144
+#define CONFIG_GENERIC_ERROR 7
1145
1146
typedef int (*config_fn_t)(const char *, const char *, void *);
1147
extern int git_default_config(const char *, const char *, void *);