5 #include "parse-options.h"
9 static const char *const builtin_config_usage
[] = {
10 N_("git config [<options>]"),
15 static regex_t
*key_regexp
;
16 static regex_t
*regexp
;
18 static int omit_values
;
19 static int use_key_regexp
;
21 static int do_not_match
;
22 static char delim
= '=';
23 static char key_delim
= ' ';
24 static char term
= '\n';
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
, type
;
29 static char *default_value
;
31 static int respect_includes_opt
= -1;
32 static struct config_options config_options
;
33 static int show_origin
;
35 #define ACTION_GET (1<<0)
36 #define ACTION_GET_ALL (1<<1)
37 #define ACTION_GET_REGEXP (1<<2)
38 #define ACTION_REPLACE_ALL (1<<3)
39 #define ACTION_ADD (1<<4)
40 #define ACTION_UNSET (1<<5)
41 #define ACTION_UNSET_ALL (1<<6)
42 #define ACTION_RENAME_SECTION (1<<7)
43 #define ACTION_REMOVE_SECTION (1<<8)
44 #define ACTION_LIST (1<<9)
45 #define ACTION_EDIT (1<<10)
46 #define ACTION_SET (1<<11)
47 #define ACTION_SET_ALL (1<<12)
48 #define ACTION_GET_COLOR (1<<13)
49 #define ACTION_GET_COLORBOOL (1<<14)
50 #define ACTION_GET_URLMATCH (1<<15)
53 * The actions "ACTION_LIST | ACTION_GET_*" which may produce more than
54 * one line of output and which should therefore be paged.
56 #define PAGING_ACTIONS (ACTION_LIST | ACTION_GET_ALL | \
57 ACTION_GET_REGEXP | ACTION_GET_URLMATCH)
61 #define TYPE_BOOL_OR_INT 3
63 #define TYPE_EXPIRY_DATE 5
66 #define OPT_CALLBACK_VALUE(s, l, v, h, i) \
67 { OPTION_CALLBACK, (s), (l), (v), NULL, (h), PARSE_OPT_NOARG | \
68 PARSE_OPT_NONEG, option_parse_type, (i) }
70 static NORETURN
void usage_builtin_config(void);
72 static int option_parse_type(const struct option
*opt
, const char *arg
,
75 int new_type
, *to_type
;
78 *((int *) opt
->value
) = 0;
83 * To support '--<type>' style flags, begin with new_type equal to
86 new_type
= opt
->defval
;
88 if (!strcmp(arg
, "bool"))
90 else if (!strcmp(arg
, "int"))
92 else if (!strcmp(arg
, "bool-or-int"))
93 new_type
= TYPE_BOOL_OR_INT
;
94 else if (!strcmp(arg
, "path"))
96 else if (!strcmp(arg
, "expiry-date"))
97 new_type
= TYPE_EXPIRY_DATE
;
98 else if (!strcmp(arg
, "color"))
99 new_type
= TYPE_COLOR
;
101 die(_("unrecognized --type argument, %s"), arg
);
104 to_type
= opt
->value
;
105 if (*to_type
&& *to_type
!= new_type
) {
107 * Complain when there is a new type not equal to the old type.
108 * This allows for combinations like '--int --type=int' and
109 * '--type=int --type=int', but disallows ones like '--type=bool
110 * --int' and '--type=bool
113 error("only one type at a time.");
114 usage_builtin_config();
121 static struct option builtin_config_options
[] = {
122 OPT_GROUP(N_("Config file location")),
123 OPT_BOOL(0, "global", &use_global_config
, N_("use global config file")),
124 OPT_BOOL(0, "system", &use_system_config
, N_("use system config file")),
125 OPT_BOOL(0, "local", &use_local_config
, N_("use repository config file")),
126 OPT_STRING('f', "file", &given_config_source
.file
, N_("file"), N_("use given config file")),
127 OPT_STRING(0, "blob", &given_config_source
.blob
, N_("blob-id"), N_("read config from given blob object")),
128 OPT_GROUP(N_("Action")),
129 OPT_BIT(0, "get", &actions
, N_("get value: name [value-regex]"), ACTION_GET
),
130 OPT_BIT(0, "get-all", &actions
, N_("get all values: key [value-regex]"), ACTION_GET_ALL
),
131 OPT_BIT(0, "get-regexp", &actions
, N_("get values for regexp: name-regex [value-regex]"), ACTION_GET_REGEXP
),
132 OPT_BIT(0, "get-urlmatch", &actions
, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH
),
133 OPT_BIT(0, "replace-all", &actions
, N_("replace all matching variables: name value [value_regex]"), ACTION_REPLACE_ALL
),
134 OPT_BIT(0, "add", &actions
, N_("add a new variable: name value"), ACTION_ADD
),
135 OPT_BIT(0, "unset", &actions
, N_("remove a variable: name [value-regex]"), ACTION_UNSET
),
136 OPT_BIT(0, "unset-all", &actions
, N_("remove all matches: name [value-regex]"), ACTION_UNSET_ALL
),
137 OPT_BIT(0, "rename-section", &actions
, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION
),
138 OPT_BIT(0, "remove-section", &actions
, N_("remove a section: name"), ACTION_REMOVE_SECTION
),
139 OPT_BIT('l', "list", &actions
, N_("list all"), ACTION_LIST
),
140 OPT_BIT('e', "edit", &actions
, N_("open an editor"), ACTION_EDIT
),
141 OPT_BIT(0, "get-color", &actions
, N_("find the color configured: slot [default]"), ACTION_GET_COLOR
),
142 OPT_BIT(0, "get-colorbool", &actions
, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL
),
143 OPT_GROUP(N_("Type")),
144 OPT_CALLBACK('t', "type", &type
, "", N_("value is given this type"), option_parse_type
),
145 OPT_CALLBACK_VALUE(0, "bool", &type
, N_("value is \"true\" or \"false\""), TYPE_BOOL
),
146 OPT_CALLBACK_VALUE(0, "int", &type
, N_("value is decimal number"), TYPE_INT
),
147 OPT_CALLBACK_VALUE(0, "bool-or-int", &type
, N_("value is --bool or --int"), TYPE_BOOL_OR_INT
),
148 OPT_CALLBACK_VALUE(0, "path", &type
, N_("value is a path (file or directory name)"), TYPE_PATH
),
149 OPT_CALLBACK_VALUE(0, "expiry-date", &type
, N_("value is an expiry date"), TYPE_EXPIRY_DATE
),
150 OPT_GROUP(N_("Other")),
151 OPT_BOOL('z', "null", &end_null
, N_("terminate values with NUL byte")),
152 OPT_BOOL(0, "name-only", &omit_values
, N_("show variable names only")),
153 OPT_BOOL(0, "includes", &respect_includes_opt
, N_("respect include directives on lookup")),
154 OPT_BOOL(0, "show-origin", &show_origin
, N_("show origin of config (file, standard input, blob, command line)")),
155 OPT_STRING(0, "default", &default_value
, N_("value"), N_("with --get, use default value when missing entry")),
159 static NORETURN
void usage_builtin_config(void)
161 usage_with_options(builtin_config_usage
, builtin_config_options
);
164 static void check_argc(int argc
, int min
, int max
) {
165 if (argc
>= min
&& argc
<= max
)
167 error("wrong number of arguments");
168 usage_builtin_config();
171 static void show_config_origin(struct strbuf
*buf
)
173 const char term
= end_null
? '\0' : '\t';
175 strbuf_addstr(buf
, current_config_origin_type());
176 strbuf_addch(buf
, ':');
178 strbuf_addstr(buf
, current_config_name());
180 quote_c_style(current_config_name(), buf
, NULL
, 0);
181 strbuf_addch(buf
, term
);
184 static int show_all_config(const char *key_
, const char *value_
, void *cb
)
187 struct strbuf buf
= STRBUF_INIT
;
188 show_config_origin(&buf
);
189 /* Use fwrite as "buf" can contain \0's if "end_null" is set. */
190 fwrite(buf
.buf
, 1, buf
.len
, stdout
);
191 strbuf_release(&buf
);
193 if (!omit_values
&& value_
)
194 printf("%s%c%s%c", key_
, delim
, value_
, term
);
196 printf("%s%c", key_
, term
);
201 struct strbuf
*items
;
206 static int format_config(struct strbuf
*buf
, const char *key_
, const char *value_
)
209 show_config_origin(buf
);
211 strbuf_addstr(buf
, key_
);
214 strbuf_addch(buf
, key_delim
);
216 if (type
== TYPE_INT
)
217 strbuf_addf(buf
, "%"PRId64
,
218 git_config_int64(key_
, value_
? value_
: ""));
219 else if (type
== TYPE_BOOL
)
220 strbuf_addstr(buf
, git_config_bool(key_
, value_
) ?
222 else if (type
== TYPE_BOOL_OR_INT
) {
224 v
= git_config_bool_or_int(key_
, value_
, &is_bool
);
226 strbuf_addstr(buf
, v
? "true" : "false");
228 strbuf_addf(buf
, "%d", v
);
229 } else if (type
== TYPE_PATH
) {
231 if (git_config_pathname(&v
, key_
, value_
) < 0)
233 strbuf_addstr(buf
, v
);
235 } else if (type
== TYPE_EXPIRY_DATE
) {
237 if (git_config_expiry_date(&t
, key_
, value_
) < 0)
239 strbuf_addf(buf
, "%"PRItime
, t
);
240 } else if (type
== TYPE_COLOR
) {
241 char v
[COLOR_MAXLEN
];
242 if (git_config_color(v
, key_
, value_
) < 0)
244 strbuf_addstr(buf
, v
);
246 strbuf_addstr(buf
, value_
);
248 /* Just show the key name; back out delimiter */
250 strbuf_setlen(buf
, buf
->len
- 1);
253 strbuf_addch(buf
, term
);
257 static int collect_config(const char *key_
, const char *value_
, void *cb
)
259 struct strbuf_list
*values
= cb
;
261 if (!use_key_regexp
&& strcmp(key_
, key
))
263 if (use_key_regexp
&& regexec(key_regexp
, key_
, 0, NULL
, 0))
265 if (regexp
!= NULL
&&
266 (do_not_match
^ !!regexec(regexp
, (value_
?value_
:""), 0, NULL
, 0)))
269 ALLOC_GROW(values
->items
, values
->nr
+ 1, values
->alloc
);
270 strbuf_init(&values
->items
[values
->nr
], 0);
272 return format_config(&values
->items
[values
->nr
++], key_
, value_
);
275 static int get_value(const char *key_
, const char *regex_
)
277 int ret
= CONFIG_GENERIC_ERROR
;
278 struct strbuf_list values
= {NULL
};
281 if (use_key_regexp
) {
285 * NEEDSWORK: this naive pattern lowercasing obviously does not
286 * work for more complex patterns like "^[^.]*Foo.*bar".
287 * Perhaps we should deprecate this altogether someday.
291 for (tl
= key
+ strlen(key
) - 1;
292 tl
>= key
&& *tl
!= '.';
295 for (tl
= key
; *tl
&& *tl
!= '.'; tl
++)
298 key_regexp
= (regex_t
*)xmalloc(sizeof(regex_t
));
299 if (regcomp(key_regexp
, key
, REG_EXTENDED
)) {
300 error("invalid key pattern: %s", key_
);
301 FREE_AND_NULL(key_regexp
);
302 ret
= CONFIG_INVALID_PATTERN
;
306 if (git_config_parse_key(key_
, &key
, NULL
)) {
307 ret
= CONFIG_INVALID_KEY
;
313 if (regex_
[0] == '!') {
318 regexp
= (regex_t
*)xmalloc(sizeof(regex_t
));
319 if (regcomp(regexp
, regex_
, REG_EXTENDED
)) {
320 error("invalid pattern: %s", regex_
);
321 FREE_AND_NULL(regexp
);
322 ret
= CONFIG_INVALID_PATTERN
;
327 config_with_options(collect_config
, &values
,
328 &given_config_source
, &config_options
);
330 if (!values
.nr
&& default_value
) {
332 ALLOC_GROW(values
.items
, values
.nr
+ 1, values
.alloc
);
333 item
= &values
.items
[values
.nr
++];
334 strbuf_init(item
, 0);
335 if (format_config(item
, key_
, default_value
) < 0)
336 die(_("failed to format default config value: %s"),
342 for (i
= 0; i
< values
.nr
; i
++) {
343 struct strbuf
*buf
= values
.items
+ i
;
344 if (do_all
|| i
== values
.nr
- 1)
345 fwrite(buf
->buf
, 1, buf
->len
, stdout
);
364 static char *normalize_value(const char *key
, const char *value
)
369 if (type
== 0 || type
== TYPE_PATH
|| type
== TYPE_EXPIRY_DATE
)
371 * We don't do normalization for TYPE_PATH here: If
372 * the path is like ~/foobar/, we prefer to store
373 * "~/foobar/" in the config file, and to expand the ~
374 * when retrieving the value.
375 * Also don't do normalization for expiry dates.
377 return xstrdup(value
);
378 if (type
== TYPE_INT
)
379 return xstrfmt("%"PRId64
, git_config_int64(key
, value
));
380 if (type
== TYPE_BOOL
)
381 return xstrdup(git_config_bool(key
, value
) ? "true" : "false");
382 if (type
== TYPE_BOOL_OR_INT
) {
384 v
= git_config_bool_or_int(key
, value
, &is_bool
);
386 return xstrfmt("%d", v
);
388 return xstrdup(v
? "true" : "false");
390 if (type
== TYPE_COLOR
) {
391 char v
[COLOR_MAXLEN
];
392 if (git_config_color(v
, key
, value
))
393 die("cannot parse color '%s'", value
);
396 * The contents of `v` now contain an ANSI escape
397 * sequence, not suitable for including within a
398 * configuration file. Treat the above as a
399 * "sanity-check", and return the given value, which we
400 * know is representable as valid color code.
402 return xstrdup(value
);
405 BUG("cannot normalize type %d", type
);
408 static int get_color_found
;
409 static const char *get_color_slot
;
410 static const char *get_colorbool_slot
;
411 static char parsed_color
[COLOR_MAXLEN
];
413 static int git_get_color_config(const char *var
, const char *value
, void *cb
)
415 if (!strcmp(var
, get_color_slot
)) {
417 config_error_nonbool(var
);
418 if (color_parse(value
, parsed_color
) < 0)
425 static void get_color(const char *var
, const char *def_color
)
427 get_color_slot
= var
;
429 parsed_color
[0] = '\0';
430 config_with_options(git_get_color_config
, NULL
,
431 &given_config_source
, &config_options
);
433 if (!get_color_found
&& def_color
) {
434 if (color_parse(def_color
, parsed_color
) < 0)
435 die(_("unable to parse default color value"));
438 fputs(parsed_color
, stdout
);
441 static int get_colorbool_found
;
442 static int get_diff_color_found
;
443 static int get_color_ui_found
;
444 static int git_get_colorbool_config(const char *var
, const char *value
,
447 if (!strcmp(var
, get_colorbool_slot
))
448 get_colorbool_found
= git_config_colorbool(var
, value
);
449 else if (!strcmp(var
, "diff.color"))
450 get_diff_color_found
= git_config_colorbool(var
, value
);
451 else if (!strcmp(var
, "color.ui"))
452 get_color_ui_found
= git_config_colorbool(var
, value
);
456 static int get_colorbool(const char *var
, int print
)
458 get_colorbool_slot
= var
;
459 get_colorbool_found
= -1;
460 get_diff_color_found
= -1;
461 get_color_ui_found
= -1;
462 config_with_options(git_get_colorbool_config
, NULL
,
463 &given_config_source
, &config_options
);
465 if (get_colorbool_found
< 0) {
466 if (!strcmp(get_colorbool_slot
, "color.diff"))
467 get_colorbool_found
= get_diff_color_found
;
468 if (get_colorbool_found
< 0)
469 get_colorbool_found
= get_color_ui_found
;
472 if (get_colorbool_found
< 0)
473 /* default value if none found in config */
474 get_colorbool_found
= GIT_COLOR_AUTO
;
476 get_colorbool_found
= want_color(get_colorbool_found
);
479 printf("%s\n", get_colorbool_found
? "true" : "false");
482 return get_colorbool_found
? 0 : 1;
485 static void check_write(void)
487 if (!given_config_source
.file
&& !startup_info
->have_repository
)
488 die("not in a git directory");
490 if (given_config_source
.use_stdin
)
491 die("writing to stdin is not supported");
493 if (given_config_source
.blob
)
494 die("writing config blobs is not supported");
497 struct urlmatch_current_candidate_value
{
502 static int urlmatch_collect_fn(const char *var
, const char *value
, void *cb
)
504 struct string_list
*values
= cb
;
505 struct string_list_item
*item
= string_list_insert(values
, var
);
506 struct urlmatch_current_candidate_value
*matched
= item
->util
;
509 matched
= xmalloc(sizeof(*matched
));
510 strbuf_init(&matched
->value
, 0);
511 item
->util
= matched
;
513 strbuf_reset(&matched
->value
);
517 strbuf_addstr(&matched
->value
, value
);
518 matched
->value_is_null
= 0;
520 matched
->value_is_null
= 1;
525 static int get_urlmatch(const char *var
, const char *url
)
529 struct string_list_item
*item
;
530 struct urlmatch_config config
= { STRING_LIST_INIT_DUP
};
531 struct string_list values
= STRING_LIST_INIT_DUP
;
533 config
.collect_fn
= urlmatch_collect_fn
;
534 config
.cascade_fn
= NULL
;
537 if (!url_normalize(url
, &config
.url
))
538 die("%s", config
.url
.err
);
540 config
.section
= xstrdup_tolower(var
);
541 section_tail
= strchr(config
.section
, '.');
543 *section_tail
= '\0';
544 config
.key
= section_tail
+ 1;
551 config_with_options(urlmatch_config_entry
, &config
,
552 &given_config_source
, &config_options
);
556 for_each_string_list_item(item
, &values
) {
557 struct urlmatch_current_candidate_value
*matched
= item
->util
;
558 struct strbuf buf
= STRBUF_INIT
;
560 format_config(&buf
, item
->string
,
561 matched
->value_is_null
? NULL
: matched
->value
.buf
);
562 fwrite(buf
.buf
, 1, buf
.len
, stdout
);
563 strbuf_release(&buf
);
565 strbuf_release(&matched
->value
);
567 string_list_clear(&config
.vars
, 1);
568 string_list_clear(&values
, 1);
569 free(config
.url
.url
);
571 free((void *)config
.section
);
575 static char *default_user_config(void)
577 struct strbuf buf
= STRBUF_INIT
;
579 _("# This is Git's per-user configuration file.\n"
581 "# Please adapt and uncomment the following lines:\n"
584 ident_default_name(),
585 ident_default_email());
586 return strbuf_detach(&buf
, NULL
);
589 int cmd_config(int argc
, const char **argv
, const char *prefix
)
591 int nongit
= !startup_info
->have_repository
;
594 given_config_source
.file
= getenv(CONFIG_ENVIRONMENT
);
596 argc
= parse_options(argc
, argv
, prefix
, builtin_config_options
,
597 builtin_config_usage
,
598 PARSE_OPT_STOP_AT_NON_OPTION
);
600 if (use_global_config
+ use_system_config
+ use_local_config
+
601 !!given_config_source
.file
+ !!given_config_source
.blob
> 1) {
602 error("only one config file at a time.");
603 usage_builtin_config();
606 if (use_local_config
&& nongit
)
607 die(_("--local can only be used inside a git repository"));
609 if (given_config_source
.blob
&& nongit
)
610 die(_("--blob can only be used inside a git repository"));
612 if (given_config_source
.file
&&
613 !strcmp(given_config_source
.file
, "-")) {
614 given_config_source
.file
= NULL
;
615 given_config_source
.use_stdin
= 1;
618 if (use_global_config
) {
619 char *user_config
= expand_user_path("~/.gitconfig", 0);
620 char *xdg_config
= xdg_config_home("config");
624 * It is unknown if HOME/.gitconfig exists, so
625 * we do not know if we should write to XDG
626 * location; error out even if XDG_CONFIG_HOME
627 * is set and points at a sane location.
629 die("$HOME not set");
631 if (access_or_warn(user_config
, R_OK
, 0) &&
632 xdg_config
&& !access_or_warn(xdg_config
, R_OK
, 0)) {
633 given_config_source
.file
= xdg_config
;
636 given_config_source
.file
= user_config
;
640 else if (use_system_config
)
641 given_config_source
.file
= git_etc_gitconfig();
642 else if (use_local_config
)
643 given_config_source
.file
= git_pathdup("config");
644 else if (given_config_source
.file
) {
645 if (!is_absolute_path(given_config_source
.file
) && prefix
)
646 given_config_source
.file
=
647 prefix_filename(prefix
, given_config_source
.file
);
650 if (respect_includes_opt
== -1)
651 config_options
.respect_includes
= !given_config_source
.file
;
653 config_options
.respect_includes
= respect_includes_opt
;
655 config_options
.commondir
= get_git_common_dir();
656 config_options
.git_dir
= get_git_dir();
665 if ((actions
& (ACTION_GET_COLOR
|ACTION_GET_COLORBOOL
)) && type
) {
666 error("--get-color and variable type are incoherent");
667 usage_builtin_config();
670 if (HAS_MULTI_BITS(actions
)) {
671 error("only one action at a time.");
672 usage_builtin_config();
676 case 1: actions
= ACTION_GET
; break;
677 case 2: actions
= ACTION_SET
; break;
678 case 3: actions
= ACTION_SET_ALL
; break;
680 usage_builtin_config();
683 !(actions
== ACTION_LIST
|| actions
== ACTION_GET_REGEXP
)) {
684 error("--name-only is only applicable to --list or --get-regexp");
685 usage_builtin_config();
688 if (show_origin
&& !(actions
&
689 (ACTION_GET
|ACTION_GET_ALL
|ACTION_GET_REGEXP
|ACTION_LIST
))) {
690 error("--show-origin is only applicable to --get, --get-all, "
691 "--get-regexp, and --list.");
692 usage_builtin_config();
695 if (default_value
&& !(actions
& ACTION_GET
)) {
696 error("--default is only applicable to --get");
697 usage_builtin_config();
700 if (actions
& PAGING_ACTIONS
)
701 setup_auto_pager("config", 1);
703 if (actions
== ACTION_LIST
) {
704 check_argc(argc
, 0, 0);
705 if (config_with_options(show_all_config
, NULL
,
706 &given_config_source
,
707 &config_options
) < 0) {
708 if (given_config_source
.file
)
709 die_errno("unable to read config file '%s'",
710 given_config_source
.file
);
712 die("error processing config file(s)");
715 else if (actions
== ACTION_EDIT
) {
718 check_argc(argc
, 0, 0);
719 if (!given_config_source
.file
&& nongit
)
720 die("not in a git directory");
721 if (given_config_source
.use_stdin
)
722 die("editing stdin is not supported");
723 if (given_config_source
.blob
)
724 die("editing blobs is not supported");
725 git_config(git_default_config
, NULL
);
726 config_file
= given_config_source
.file
?
727 xstrdup(given_config_source
.file
) :
728 git_pathdup("config");
729 if (use_global_config
) {
730 int fd
= open(config_file
, O_CREAT
| O_EXCL
| O_WRONLY
, 0666);
732 char *content
= default_user_config();
733 write_str_in_full(fd
, content
);
737 else if (errno
!= EEXIST
)
738 die_errno(_("cannot create configuration file %s"), config_file
);
740 launch_editor(config_file
, NULL
, NULL
);
743 else if (actions
== ACTION_SET
) {
746 check_argc(argc
, 2, 2);
747 value
= normalize_value(argv
[0], argv
[1]);
749 ret
= git_config_set_in_file_gently(given_config_source
.file
, argv
[0], value
);
750 if (ret
== CONFIG_NOTHING_SET
)
751 error(_("cannot overwrite multiple values with a single value\n"
752 " Use a regexp, --add or --replace-all to change %s."), argv
[0]);
755 else if (actions
== ACTION_SET_ALL
) {
757 check_argc(argc
, 2, 3);
758 value
= normalize_value(argv
[0], argv
[1]);
760 return git_config_set_multivar_in_file_gently(given_config_source
.file
,
761 argv
[0], value
, argv
[2], 0);
763 else if (actions
== ACTION_ADD
) {
765 check_argc(argc
, 2, 2);
766 value
= normalize_value(argv
[0], argv
[1]);
768 return git_config_set_multivar_in_file_gently(given_config_source
.file
,
770 CONFIG_REGEX_NONE
, 0);
772 else if (actions
== ACTION_REPLACE_ALL
) {
774 check_argc(argc
, 2, 3);
775 value
= normalize_value(argv
[0], argv
[1]);
777 return git_config_set_multivar_in_file_gently(given_config_source
.file
,
778 argv
[0], value
, argv
[2], 1);
780 else if (actions
== ACTION_GET
) {
781 check_argc(argc
, 1, 2);
782 return get_value(argv
[0], argv
[1]);
784 else if (actions
== ACTION_GET_ALL
) {
786 check_argc(argc
, 1, 2);
787 return get_value(argv
[0], argv
[1]);
789 else if (actions
== ACTION_GET_REGEXP
) {
793 check_argc(argc
, 1, 2);
794 return get_value(argv
[0], argv
[1]);
796 else if (actions
== ACTION_GET_URLMATCH
) {
797 check_argc(argc
, 2, 2);
798 return get_urlmatch(argv
[0], argv
[1]);
800 else if (actions
== ACTION_UNSET
) {
802 check_argc(argc
, 1, 2);
804 return git_config_set_multivar_in_file_gently(given_config_source
.file
,
805 argv
[0], NULL
, argv
[1], 0);
807 return git_config_set_in_file_gently(given_config_source
.file
,
810 else if (actions
== ACTION_UNSET_ALL
) {
812 check_argc(argc
, 1, 2);
813 return git_config_set_multivar_in_file_gently(given_config_source
.file
,
814 argv
[0], NULL
, argv
[1], 1);
816 else if (actions
== ACTION_RENAME_SECTION
) {
819 check_argc(argc
, 2, 2);
820 ret
= git_config_rename_section_in_file(given_config_source
.file
,
825 die("No such section!");
827 else if (actions
== ACTION_REMOVE_SECTION
) {
830 check_argc(argc
, 1, 1);
831 ret
= git_config_rename_section_in_file(given_config_source
.file
,
836 die("No such section!");
838 else if (actions
== ACTION_GET_COLOR
) {
839 check_argc(argc
, 1, 2);
840 get_color(argv
[0], argv
[1]);
842 else if (actions
== ACTION_GET_COLORBOOL
) {
843 check_argc(argc
, 1, 2);
845 color_stdout_is_tty
= git_config_bool("command line", argv
[1]);
846 return get_colorbool(argv
[0], argc
== 2);