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