Skip to content

Commit 9409c7a

Browse files
committed
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 <[email protected]>
1 parent 785ee49 commit 9409c7a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Documentation/git-config.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ configuration file by default, and options '--system', '--global',
5454
'--file <filename>' can be used to tell the command to write to
5555
that location (you can say '--local' but that is the default).
5656

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:
5859

5960
. The config file is invalid (ret=3),
6061
. can not write to the config file (ret=4),
6162
. no section or name was provided (ret=2),
6263
. the section or key is invalid (ret=1),
6364
. 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).
6767

6868
On success, the command returns the exit code 0.
6969

builtin/config.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
160160

161161
static int get_value(const char *key_, const char *regex_)
162162
{
163-
int ret = -1;
163+
int ret = CONFIG_GENERIC_ERROR;
164164
char *global = NULL, *repo_config = NULL;
165165
const char *system_wide = NULL, *local;
166166
struct config_include_data inc = CONFIG_INCLUDE_INIT;
@@ -198,11 +198,14 @@ static int get_value(const char *key_, const char *regex_)
198198
if (regcomp(key_regexp, key, REG_EXTENDED)) {
199199
fprintf(stderr, "Invalid key pattern: %s\n", key_);
200200
free(key);
201+
ret = CONFIG_INVALID_PATTERN;
201202
goto free_strings;
202203
}
203204
} else {
204-
if (git_config_parse_key(key_, &key, NULL))
205+
if (git_config_parse_key(key_, &key, NULL)) {
206+
ret = CONFIG_INVALID_KEY;
205207
goto free_strings;
208+
}
206209
}
207210

208211
if (regex_) {
@@ -214,6 +217,7 @@ static int get_value(const char *key_, const char *regex_)
214217
regexp = (regex_t*)xmalloc(sizeof(regex_t));
215218
if (regcomp(regexp, regex_, REG_EXTENDED)) {
216219
fprintf(stderr, "Invalid pattern: %s\n", regex_);
220+
ret = CONFIG_INVALID_PATTERN;
217221
goto free_strings;
218222
}
219223
}

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ extern int update_server_info(int);
11411141
#define CONFIG_NO_WRITE 4
11421142
#define CONFIG_NOTHING_SET 5
11431143
#define CONFIG_INVALID_PATTERN 6
1144+
#define CONFIG_GENERIC_ERROR 7
11441145

11451146
typedef int (*config_fn_t)(const char *, const char *, void *);
11461147
extern int git_default_config(const char *, const char *, void *);

0 commit comments

Comments
 (0)