Merge branch 'jk/warn-add-gitlink'
[git] / builtin / config.c
1 #include "builtin.h"
2 #include "cache.h"
3 #include "config.h"
4 #include "color.h"
5 #include "parse-options.h"
6 #include "urlmatch.h"
7 #include "quote.h"
8
9 static const char *const builtin_config_usage[] = {
10         N_("git config [<options>]"),
11         NULL
12 };
13
14 static char *key;
15 static regex_t *key_regexp;
16 static regex_t *regexp;
17 static int show_keys;
18 static int omit_values;
19 static int use_key_regexp;
20 static int do_all;
21 static int do_not_match;
22 static char delim = '=';
23 static char key_delim = ' ';
24 static char term = '\n';
25
26 static int use_global_config, use_system_config, use_local_config;
27 static struct git_config_source given_config_source;
28 static int actions, types;
29 static int end_null;
30 static int respect_includes_opt = -1;
31 static struct config_options config_options;
32 static int show_origin;
33
34 #define ACTION_GET (1<<0)
35 #define ACTION_GET_ALL (1<<1)
36 #define ACTION_GET_REGEXP (1<<2)
37 #define ACTION_REPLACE_ALL (1<<3)
38 #define ACTION_ADD (1<<4)
39 #define ACTION_UNSET (1<<5)
40 #define ACTION_UNSET_ALL (1<<6)
41 #define ACTION_RENAME_SECTION (1<<7)
42 #define ACTION_REMOVE_SECTION (1<<8)
43 #define ACTION_LIST (1<<9)
44 #define ACTION_EDIT (1<<10)
45 #define ACTION_SET (1<<11)
46 #define ACTION_SET_ALL (1<<12)
47 #define ACTION_GET_COLOR (1<<13)
48 #define ACTION_GET_COLORBOOL (1<<14)
49 #define ACTION_GET_URLMATCH (1<<15)
50
51 #define TYPE_BOOL (1<<0)
52 #define TYPE_INT (1<<1)
53 #define TYPE_BOOL_OR_INT (1<<2)
54 #define TYPE_PATH (1<<3)
55
56 static struct option builtin_config_options[] = {
57         OPT_GROUP(N_("Config file location")),
58         OPT_BOOL(0, "global", &use_global_config, N_("use global config file")),
59         OPT_BOOL(0, "system", &use_system_config, N_("use system config file")),
60         OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")),
61         OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")),
62         OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")),
63         OPT_GROUP(N_("Action")),
64         OPT_BIT(0, "get", &actions, N_("get value: name [value-regex]"), ACTION_GET),
65         OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-regex]"), ACTION_GET_ALL),
66         OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-regex]"), ACTION_GET_REGEXP),
67         OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH),
68         OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value_regex]"), ACTION_REPLACE_ALL),
69         OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD),
70         OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-regex]"), ACTION_UNSET),
71         OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-regex]"), ACTION_UNSET_ALL),
72         OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION),
73         OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
74         OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST),
75         OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT),
76         OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR),
77         OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL),
78         OPT_GROUP(N_("Type")),
79         OPT_BIT(0, "bool", &types, N_("value is \"true\" or \"false\""), TYPE_BOOL),
80         OPT_BIT(0, "int", &types, N_("value is decimal number"), TYPE_INT),
81         OPT_BIT(0, "bool-or-int", &types, N_("value is --bool or --int"), TYPE_BOOL_OR_INT),
82         OPT_BIT(0, "path", &types, N_("value is a path (file or directory name)"), TYPE_PATH),
83         OPT_GROUP(N_("Other")),
84         OPT_BOOL('z', "null", &end_null, N_("terminate values with NUL byte")),
85         OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")),
86         OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")),
87         OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")),
88         OPT_END(),
89 };
90
91 static void check_argc(int argc, int min, int max) {
92         if (argc >= min && argc <= max)
93                 return;
94         error("wrong number of arguments");
95         usage_with_options(builtin_config_usage, builtin_config_options);
96 }
97
98 static void show_config_origin(struct strbuf *buf)
99 {
100         const char term = end_null ? '\0' : '\t';
101
102         strbuf_addstr(buf, current_config_origin_type());
103         strbuf_addch(buf, ':');
104         if (end_null)
105                 strbuf_addstr(buf, current_config_name());
106         else
107                 quote_c_style(current_config_name(), buf, NULL, 0);
108         strbuf_addch(buf, term);
109 }
110
111 static int show_all_config(const char *key_, const char *value_, void *cb)
112 {
113         if (show_origin) {
114                 struct strbuf buf = STRBUF_INIT;
115                 show_config_origin(&buf);
116                 /* Use fwrite as "buf" can contain \0's if "end_null" is set. */
117                 fwrite(buf.buf, 1, buf.len, stdout);
118                 strbuf_release(&buf);
119         }
120         if (!omit_values && value_)
121                 printf("%s%c%s%c", key_, delim, value_, term);
122         else
123                 printf("%s%c", key_, term);
124         return 0;
125 }
126
127 struct strbuf_list {
128         struct strbuf *items;
129         int nr;
130         int alloc;
131 };
132
133 static int format_config(struct strbuf *buf, const char *key_, const char *value_)
134 {
135         if (show_origin)
136                 show_config_origin(buf);
137         if (show_keys)
138                 strbuf_addstr(buf, key_);
139         if (!omit_values) {
140                 if (show_keys)
141                         strbuf_addch(buf, key_delim);
142
143                 if (types == TYPE_INT)
144                         strbuf_addf(buf, "%"PRId64,
145                                     git_config_int64(key_, value_ ? value_ : ""));
146                 else if (types == TYPE_BOOL)
147                         strbuf_addstr(buf, git_config_bool(key_, value_) ?
148                                       "true" : "false");
149                 else if (types == TYPE_BOOL_OR_INT) {
150                         int is_bool, v;
151                         v = git_config_bool_or_int(key_, value_, &is_bool);
152                         if (is_bool)
153                                 strbuf_addstr(buf, v ? "true" : "false");
154                         else
155                                 strbuf_addf(buf, "%d", v);
156                 } else if (types == TYPE_PATH) {
157                         const char *v;
158                         if (git_config_pathname(&v, key_, value_) < 0)
159                                 return -1;
160                         strbuf_addstr(buf, v);
161                         free((char *)v);
162                 } else if (value_) {
163                         strbuf_addstr(buf, value_);
164                 } else {
165                         /* Just show the key name; back out delimiter */
166                         if (show_keys)
167                                 strbuf_setlen(buf, buf->len - 1);
168                 }
169         }
170         strbuf_addch(buf, term);
171         return 0;
172 }
173
174 static int collect_config(const char *key_, const char *value_, void *cb)
175 {
176         struct strbuf_list *values = cb;
177
178         if (!use_key_regexp && strcmp(key_, key))
179                 return 0;
180         if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))
181                 return 0;
182         if (regexp != NULL &&
183             (do_not_match ^ !!regexec(regexp, (value_?value_:""), 0, NULL, 0)))
184                 return 0;
185
186         ALLOC_GROW(values->items, values->nr + 1, values->alloc);
187         strbuf_init(&values->items[values->nr], 0);
188
189         return format_config(&values->items[values->nr++], key_, value_);
190 }
191
192 static int get_value(const char *key_, const char *regex_)
193 {
194         int ret = CONFIG_GENERIC_ERROR;
195         struct strbuf_list values = {NULL};
196         int i;
197
198         if (use_key_regexp) {
199                 char *tl;
200
201                 /*
202                  * NEEDSWORK: this naive pattern lowercasing obviously does not
203                  * work for more complex patterns like "^[^.]*Foo.*bar".
204                  * Perhaps we should deprecate this altogether someday.
205                  */
206
207                 key = xstrdup(key_);
208                 for (tl = key + strlen(key) - 1;
209                      tl >= key && *tl != '.';
210                      tl--)
211                         *tl = tolower(*tl);
212                 for (tl = key; *tl && *tl != '.'; tl++)
213                         *tl = tolower(*tl);
214
215                 key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
216                 if (regcomp(key_regexp, key, REG_EXTENDED)) {
217                         error("invalid key pattern: %s", key_);
218                         free(key_regexp);
219                         key_regexp = NULL;
220                         ret = CONFIG_INVALID_PATTERN;
221                         goto free_strings;
222                 }
223         } else {
224                 if (git_config_parse_key(key_, &key, NULL)) {
225                         ret = CONFIG_INVALID_KEY;
226                         goto free_strings;
227                 }
228         }
229
230         if (regex_) {
231                 if (regex_[0] == '!') {
232                         do_not_match = 1;
233                         regex_++;
234                 }
235
236                 regexp = (regex_t*)xmalloc(sizeof(regex_t));
237                 if (regcomp(regexp, regex_, REG_EXTENDED)) {
238                         error("invalid pattern: %s", regex_);
239                         free(regexp);
240                         regexp = NULL;
241                         ret = CONFIG_INVALID_PATTERN;
242                         goto free_strings;
243                 }
244         }
245
246         config_with_options(collect_config, &values,
247                             &given_config_source, &config_options);
248
249         ret = !values.nr;
250
251         for (i = 0; i < values.nr; i++) {
252                 struct strbuf *buf = values.items + i;
253                 if (do_all || i == values.nr - 1)
254                         fwrite(buf->buf, 1, buf->len, stdout);
255                 strbuf_release(buf);
256         }
257         free(values.items);
258
259 free_strings:
260         free(key);
261         if (key_regexp) {
262                 regfree(key_regexp);
263                 free(key_regexp);
264         }
265         if (regexp) {
266                 regfree(regexp);
267                 free(regexp);
268         }
269
270         return ret;
271 }
272
273 static char *normalize_value(const char *key, const char *value)
274 {
275         if (!value)
276                 return NULL;
277
278         if (types == 0 || types == TYPE_PATH)
279                 /*
280                  * We don't do normalization for TYPE_PATH here: If
281                  * the path is like ~/foobar/, we prefer to store
282                  * "~/foobar/" in the config file, and to expand the ~
283                  * when retrieving the value.
284                  */
285                 return xstrdup(value);
286         if (types == TYPE_INT)
287                 return xstrfmt("%"PRId64, git_config_int64(key, value));
288         if (types == TYPE_BOOL)
289                 return xstrdup(git_config_bool(key, value) ?  "true" : "false");
290         if (types == TYPE_BOOL_OR_INT) {
291                 int is_bool, v;
292                 v = git_config_bool_or_int(key, value, &is_bool);
293                 if (!is_bool)
294                         return xstrfmt("%d", v);
295                 else
296                         return xstrdup(v ? "true" : "false");
297         }
298
299         die("BUG: cannot normalize type %d", types);
300 }
301
302 static int get_color_found;
303 static const char *get_color_slot;
304 static const char *get_colorbool_slot;
305 static char parsed_color[COLOR_MAXLEN];
306
307 static int git_get_color_config(const char *var, const char *value, void *cb)
308 {
309         if (!strcmp(var, get_color_slot)) {
310                 if (!value)
311                         config_error_nonbool(var);
312                 if (color_parse(value, parsed_color) < 0)
313                         return -1;
314                 get_color_found = 1;
315         }
316         return 0;
317 }
318
319 static void get_color(const char *var, const char *def_color)
320 {
321         get_color_slot = var;
322         get_color_found = 0;
323         parsed_color[0] = '\0';
324         config_with_options(git_get_color_config, NULL,
325                             &given_config_source, &config_options);
326
327         if (!get_color_found && def_color) {
328                 if (color_parse(def_color, parsed_color) < 0)
329                         die(_("unable to parse default color value"));
330         }
331
332         fputs(parsed_color, stdout);
333 }
334
335 static int get_colorbool_found;
336 static int get_diff_color_found;
337 static int get_color_ui_found;
338 static int git_get_colorbool_config(const char *var, const char *value,
339                 void *cb)
340 {
341         if (!strcmp(var, get_colorbool_slot))
342                 get_colorbool_found = git_config_colorbool(var, value);
343         else if (!strcmp(var, "diff.color"))
344                 get_diff_color_found = git_config_colorbool(var, value);
345         else if (!strcmp(var, "color.ui"))
346                 get_color_ui_found = git_config_colorbool(var, value);
347         return 0;
348 }
349
350 static int get_colorbool(const char *var, int print)
351 {
352         get_colorbool_slot = var;
353         get_colorbool_found = -1;
354         get_diff_color_found = -1;
355         get_color_ui_found = -1;
356         config_with_options(git_get_colorbool_config, NULL,
357                             &given_config_source, &config_options);
358
359         if (get_colorbool_found < 0) {
360                 if (!strcmp(get_colorbool_slot, "color.diff"))
361                         get_colorbool_found = get_diff_color_found;
362                 if (get_colorbool_found < 0)
363                         get_colorbool_found = get_color_ui_found;
364         }
365
366         if (get_colorbool_found < 0)
367                 /* default value if none found in config */
368                 get_colorbool_found = GIT_COLOR_AUTO;
369
370         get_colorbool_found = want_color(get_colorbool_found);
371
372         if (print) {
373                 printf("%s\n", get_colorbool_found ? "true" : "false");
374                 return 0;
375         } else
376                 return get_colorbool_found ? 0 : 1;
377 }
378
379 static void check_write(void)
380 {
381         if (!given_config_source.file && !startup_info->have_repository)
382                 die("not in a git directory");
383
384         if (given_config_source.use_stdin)
385                 die("writing to stdin is not supported");
386
387         if (given_config_source.blob)
388                 die("writing config blobs is not supported");
389 }
390
391 struct urlmatch_current_candidate_value {
392         char value_is_null;
393         struct strbuf value;
394 };
395
396 static int urlmatch_collect_fn(const char *var, const char *value, void *cb)
397 {
398         struct string_list *values = cb;
399         struct string_list_item *item = string_list_insert(values, var);
400         struct urlmatch_current_candidate_value *matched = item->util;
401
402         if (!matched) {
403                 matched = xmalloc(sizeof(*matched));
404                 strbuf_init(&matched->value, 0);
405                 item->util = matched;
406         } else {
407                 strbuf_reset(&matched->value);
408         }
409
410         if (value) {
411                 strbuf_addstr(&matched->value, value);
412                 matched->value_is_null = 0;
413         } else {
414                 matched->value_is_null = 1;
415         }
416         return 0;
417 }
418
419 static int get_urlmatch(const char *var, const char *url)
420 {
421         int ret;
422         char *section_tail;
423         struct string_list_item *item;
424         struct urlmatch_config config = { STRING_LIST_INIT_DUP };
425         struct string_list values = STRING_LIST_INIT_DUP;
426
427         config.collect_fn = urlmatch_collect_fn;
428         config.cascade_fn = NULL;
429         config.cb = &values;
430
431         if (!url_normalize(url, &config.url))
432                 die("%s", config.url.err);
433
434         config.section = xstrdup_tolower(var);
435         section_tail = strchr(config.section, '.');
436         if (section_tail) {
437                 *section_tail = '\0';
438                 config.key = section_tail + 1;
439                 show_keys = 0;
440         } else {
441                 config.key = NULL;
442                 show_keys = 1;
443         }
444
445         config_with_options(urlmatch_config_entry, &config,
446                             &given_config_source, &config_options);
447
448         ret = !values.nr;
449
450         for_each_string_list_item(item, &values) {
451                 struct urlmatch_current_candidate_value *matched = item->util;
452                 struct strbuf buf = STRBUF_INIT;
453
454                 format_config(&buf, item->string,
455                               matched->value_is_null ? NULL : matched->value.buf);
456                 fwrite(buf.buf, 1, buf.len, stdout);
457                 strbuf_release(&buf);
458
459                 strbuf_release(&matched->value);
460         }
461         string_list_clear(&config.vars, 1);
462         string_list_clear(&values, 1);
463         free(config.url.url);
464
465         free((void *)config.section);
466         return ret;
467 }
468
469 static char *default_user_config(void)
470 {
471         struct strbuf buf = STRBUF_INIT;
472         strbuf_addf(&buf,
473                     _("# This is Git's per-user configuration file.\n"
474                       "[user]\n"
475                       "# Please adapt and uncomment the following lines:\n"
476                       "#        name = %s\n"
477                       "#        email = %s\n"),
478                     ident_default_name(),
479                     ident_default_email());
480         return strbuf_detach(&buf, NULL);
481 }
482
483 int cmd_config(int argc, const char **argv, const char *prefix)
484 {
485         int nongit = !startup_info->have_repository;
486         char *value;
487
488         given_config_source.file = getenv(CONFIG_ENVIRONMENT);
489
490         argc = parse_options(argc, argv, prefix, builtin_config_options,
491                              builtin_config_usage,
492                              PARSE_OPT_STOP_AT_NON_OPTION);
493
494         if (use_global_config + use_system_config + use_local_config +
495             !!given_config_source.file + !!given_config_source.blob > 1) {
496                 error("only one config file at a time.");
497                 usage_with_options(builtin_config_usage, builtin_config_options);
498         }
499
500         if (use_local_config && nongit)
501                 die(_("--local can only be used inside a git repository"));
502
503         if (given_config_source.file &&
504                         !strcmp(given_config_source.file, "-")) {
505                 given_config_source.file = NULL;
506                 given_config_source.use_stdin = 1;
507         }
508
509         if (use_global_config) {
510                 char *user_config = expand_user_path("~/.gitconfig", 0);
511                 char *xdg_config = xdg_config_home("config");
512
513                 if (!user_config)
514                         /*
515                          * It is unknown if HOME/.gitconfig exists, so
516                          * we do not know if we should write to XDG
517                          * location; error out even if XDG_CONFIG_HOME
518                          * is set and points at a sane location.
519                          */
520                         die("$HOME not set");
521
522                 if (access_or_warn(user_config, R_OK, 0) &&
523                     xdg_config && !access_or_warn(xdg_config, R_OK, 0))
524                         given_config_source.file = xdg_config;
525                 else
526                         given_config_source.file = user_config;
527         }
528         else if (use_system_config)
529                 given_config_source.file = git_etc_gitconfig();
530         else if (use_local_config)
531                 given_config_source.file = git_pathdup("config");
532         else if (given_config_source.file) {
533                 if (!is_absolute_path(given_config_source.file) && prefix)
534                         given_config_source.file =
535                                 prefix_filename(prefix, given_config_source.file);
536         }
537
538         if (respect_includes_opt == -1)
539                 config_options.respect_includes = !given_config_source.file;
540         else
541                 config_options.respect_includes = respect_includes_opt;
542         if (!nongit) {
543                 config_options.commondir = get_git_common_dir();
544                 config_options.git_dir = get_git_dir();
545         }
546
547         if (end_null) {
548                 term = '\0';
549                 delim = '\n';
550                 key_delim = '\n';
551         }
552
553         if (HAS_MULTI_BITS(types)) {
554                 error("only one type at a time.");
555                 usage_with_options(builtin_config_usage, builtin_config_options);
556         }
557
558         if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && types) {
559                 error("--get-color and variable type are incoherent");
560                 usage_with_options(builtin_config_usage, builtin_config_options);
561         }
562
563         if (HAS_MULTI_BITS(actions)) {
564                 error("only one action at a time.");
565                 usage_with_options(builtin_config_usage, builtin_config_options);
566         }
567         if (actions == 0)
568                 switch (argc) {
569                 case 1: actions = ACTION_GET; break;
570                 case 2: actions = ACTION_SET; break;
571                 case 3: actions = ACTION_SET_ALL; break;
572                 default:
573                         usage_with_options(builtin_config_usage, builtin_config_options);
574                 }
575         if (omit_values &&
576             !(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) {
577                 error("--name-only is only applicable to --list or --get-regexp");
578                 usage_with_options(builtin_config_usage, builtin_config_options);
579         }
580
581         if (show_origin && !(actions &
582                 (ACTION_GET|ACTION_GET_ALL|ACTION_GET_REGEXP|ACTION_LIST))) {
583                 error("--show-origin is only applicable to --get, --get-all, "
584                           "--get-regexp, and --list.");
585                 usage_with_options(builtin_config_usage, builtin_config_options);
586         }
587
588         if (actions == ACTION_LIST) {
589                 check_argc(argc, 0, 0);
590                 if (config_with_options(show_all_config, NULL,
591                                         &given_config_source,
592                                         &config_options) < 0) {
593                         if (given_config_source.file)
594                                 die_errno("unable to read config file '%s'",
595                                           given_config_source.file);
596                         else
597                                 die("error processing config file(s)");
598                 }
599         }
600         else if (actions == ACTION_EDIT) {
601                 char *config_file;
602
603                 check_argc(argc, 0, 0);
604                 if (!given_config_source.file && nongit)
605                         die("not in a git directory");
606                 if (given_config_source.use_stdin)
607                         die("editing stdin is not supported");
608                 if (given_config_source.blob)
609                         die("editing blobs is not supported");
610                 git_config(git_default_config, NULL);
611                 config_file = given_config_source.file ?
612                                 xstrdup(given_config_source.file) :
613                                 git_pathdup("config");
614                 if (use_global_config) {
615                         int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666);
616                         if (fd >= 0) {
617                                 char *content = default_user_config();
618                                 write_str_in_full(fd, content);
619                                 free(content);
620                                 close(fd);
621                         }
622                         else if (errno != EEXIST)
623                                 die_errno(_("cannot create configuration file %s"), config_file);
624                 }
625                 launch_editor(config_file, NULL, NULL);
626                 free(config_file);
627         }
628         else if (actions == ACTION_SET) {
629                 int ret;
630                 check_write();
631                 check_argc(argc, 2, 2);
632                 value = normalize_value(argv[0], argv[1]);
633                 ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value);
634                 if (ret == CONFIG_NOTHING_SET)
635                         error(_("cannot overwrite multiple values with a single value\n"
636                         "       Use a regexp, --add or --replace-all to change %s."), argv[0]);
637                 return ret;
638         }
639         else if (actions == ACTION_SET_ALL) {
640                 check_write();
641                 check_argc(argc, 2, 3);
642                 value = normalize_value(argv[0], argv[1]);
643                 return git_config_set_multivar_in_file_gently(given_config_source.file,
644                                                               argv[0], value, argv[2], 0);
645         }
646         else if (actions == ACTION_ADD) {
647                 check_write();
648                 check_argc(argc, 2, 2);
649                 value = normalize_value(argv[0], argv[1]);
650                 return git_config_set_multivar_in_file_gently(given_config_source.file,
651                                                               argv[0], value,
652                                                               CONFIG_REGEX_NONE, 0);
653         }
654         else if (actions == ACTION_REPLACE_ALL) {
655                 check_write();
656                 check_argc(argc, 2, 3);
657                 value = normalize_value(argv[0], argv[1]);
658                 return git_config_set_multivar_in_file_gently(given_config_source.file,
659                                                               argv[0], value, argv[2], 1);
660         }
661         else if (actions == ACTION_GET) {
662                 check_argc(argc, 1, 2);
663                 return get_value(argv[0], argv[1]);
664         }
665         else if (actions == ACTION_GET_ALL) {
666                 do_all = 1;
667                 check_argc(argc, 1, 2);
668                 return get_value(argv[0], argv[1]);
669         }
670         else if (actions == ACTION_GET_REGEXP) {
671                 show_keys = 1;
672                 use_key_regexp = 1;
673                 do_all = 1;
674                 check_argc(argc, 1, 2);
675                 return get_value(argv[0], argv[1]);
676         }
677         else if (actions == ACTION_GET_URLMATCH) {
678                 check_argc(argc, 2, 2);
679                 return get_urlmatch(argv[0], argv[1]);
680         }
681         else if (actions == ACTION_UNSET) {
682                 check_write();
683                 check_argc(argc, 1, 2);
684                 if (argc == 2)
685                         return git_config_set_multivar_in_file_gently(given_config_source.file,
686                                                                       argv[0], NULL, argv[1], 0);
687                 else
688                         return git_config_set_in_file_gently(given_config_source.file,
689                                                              argv[0], NULL);
690         }
691         else if (actions == ACTION_UNSET_ALL) {
692                 check_write();
693                 check_argc(argc, 1, 2);
694                 return git_config_set_multivar_in_file_gently(given_config_source.file,
695                                                               argv[0], NULL, argv[1], 1);
696         }
697         else if (actions == ACTION_RENAME_SECTION) {
698                 int ret;
699                 check_write();
700                 check_argc(argc, 2, 2);
701                 ret = git_config_rename_section_in_file(given_config_source.file,
702                                                         argv[0], argv[1]);
703                 if (ret < 0)
704                         return ret;
705                 if (ret == 0)
706                         die("No such section!");
707         }
708         else if (actions == ACTION_REMOVE_SECTION) {
709                 int ret;
710                 check_write();
711                 check_argc(argc, 1, 1);
712                 ret = git_config_rename_section_in_file(given_config_source.file,
713                                                         argv[0], NULL);
714                 if (ret < 0)
715                         return ret;
716                 if (ret == 0)
717                         die("No such section!");
718         }
719         else if (actions == ACTION_GET_COLOR) {
720                 check_argc(argc, 1, 2);
721                 get_color(argv[0], argv[1]);
722         }
723         else if (actions == ACTION_GET_COLORBOOL) {
724                 check_argc(argc, 1, 2);
725                 if (argc == 2)
726                         color_stdout_is_tty = git_config_bool("command line", argv[1]);
727                 return get_colorbool(argv[0], argc == 2);
728         }
729
730         return 0;
731 }