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