path: root/builtin/config.c
diff options
authorSZEDER Gábor <>2015-08-10 09:46:06 (GMT)
committerJunio C Hamano <>2015-08-10 17:33:58 (GMT)
commit578625fa918922713a2ecce2b06611e4566778f5 (patch)
treec52e008410a474e5640c02d1093e1cb99e29cce9 /builtin/config.c
parent77bd3ea9f54f1584147b594abc04c26ca516d987 (diff)
config: add '--name-only' option to list only variable names
'git config' can only show values or name-value pairs, so if a shell script needs the names of set config variables it has to run 'git config --list' or '--get-regexp' and parse the output to separate config variable names from their values. However, such a parsing can't cope with multi-line values. Though 'git config' can produce null-terminated output for newline-safe parsing, that's of no use in such a case, becase shells can't cope with null characters. Even our own bash completion script suffers from these issues. Help the completion script, and shell scripts in general, by introducing the '--name-only' option to modify the output of '--list' and '--get-regexp' to list only the names of config variables, so they don't have to perform error-prone post processing to separate variable names from their values anymore. Signed-off-by: SZEDER Gábor <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/config.c')
1 files changed, 12 insertions, 2 deletions
diff --git a/builtin/config.c b/builtin/config.c
index 7188405..631db45 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -13,6 +13,7 @@ static char *key;
static regex_t *key_regexp;
static regex_t *regexp;
static int show_keys;
+static int omit_values;
static int use_key_regexp;
static int do_all;
static int do_not_match;
@@ -78,6 +79,7 @@ static struct option builtin_config_options[] = {
OPT_BIT(0, "path", &types, N_("value is a path (file or directory name)"), TYPE_PATH),
OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
+ OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),
OPT_BOOL(0, "includes", &respect_includes, N_("respect include directives on lookup")),
@@ -91,7 +93,7 @@ static void check_argc(int argc, int min, int max) {
static int show_all_config(const char *key_, const char *value_, void *cb)
- if (value_)
+ if (!omit_values && value_)
printf("%s%c%s%c", key_, delim, value_, term);
printf("%s%c", key_, term);
@@ -117,6 +119,10 @@ static int format_config(struct strbuf *buf, const char *key_, const char *value
strbuf_addstr(buf, key_);
must_print_delim = 1;
+ if (omit_values) {
+ strbuf_addch(buf, term);
+ return 0;
+ }
if (types == TYPE_INT)
sprintf(value, "%"PRId64,
git_config_int64(key_, value_ ? value_ : ""));
@@ -549,7 +555,11 @@ int cmd_config(int argc, const char **argv, const char *prefix)
usage_with_options(builtin_config_usage, builtin_config_options);
+ if (omit_values &&
+ !(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) {
+ error("--name-only is only applicable to --list or --get-regexp");
+ usage_with_options(builtin_config_usage, builtin_config_options);
+ }
if (actions == ACTION_LIST) {
check_argc(argc, 0, 0);
if (git_config_with_options(show_all_config, NULL,