Add --add option to git-repo-config
For multivars, the "git-repo-config name value ^$" is useful but nonintuitive and troublesome to do repeatedly (since the value is not at the end of the command line). This commit simply adds an --add option that adds a new value to a multivar. Particularly useful for tracking a new branch on a remote: git-repo-config --add remote.origin.fetch +next:origin/next Includes documentation and test. Signed-off-by: Brian Gernhardt <benji@silverinsanity.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Brian Gernhardt committed
Dec 15, 2006 at 07:39 UTC
89c4afe0d011b71d0bbcd9ad43f367f6a0dc3d83
3 files changed
+27
-3
Documentation/git-repo-config.txt
+13
-1
@@ -10,6 +10,7 @@ SYNOPSIS
10
--------
11
[verse]
12
'git-repo-config' [--global] [type] name [value [value_regex]]
13
+'git-repo-config' [--global] [type] --add name value
14
'git-repo-config' [--global] [type] --replace-all name [value [value_regex]]
15
'git-repo-config' [--global] [type] --get name [value_regex]
16
'git-repo-config' [--global] [type] --get-all name [value_regex]
@@ -23,7 +24,8 @@ You can query/set/replace/unset options with this command. The name is
24
actually the section and the key separated by a dot, and the value will be
25
escaped.
26
26
-If you want to set/unset an option which can occur on multiple
27
+Multiple lines can be added to an option by using the '--add' option.
28
+If you want to update or unset an option which can occur on multiple
29
lines, a POSIX regexp `value_regex` needs to be given. Only the
30
existing values that match the regexp are updated or unset. If
31
you want to handle the lines that do *not* match the regex, just
@@ -53,6 +55,10 @@ OPTIONS
55
Default behavior is to replace at most one line. This replaces
56
all lines matching the key (and optionally the value_regex).
57
58
+--add::
59
+ Adds a new line to the option without altering any existing
60
+ values. This is the same as providing '^$' as the value_regex.
61
+
62
--get::
63
Get the value for a given key (optionally filtered by a regex
64
matching the value). Returns error code 1 if the key was not
@@ -194,6 +200,12 @@ To actually match only values with an exclamation mark, you have to
200
% git repo-config section.key value '[!]'
201
------------
202
203
+To add a new proxy, without altering any of the existing ones, use
204
+
205
+------------
206
+% git repo-config core.gitproxy '"proxy" for example.com'
207
+------------
208
+
209
210
include::config.txt[]
211
builtin-repo-config.c
+4
-2
@@ -3,7 +3,7 @@
3
#include <regex.h>
4
5
static const char git_config_set_usage[] =
6
-"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --unset | --unset-all] name [value [value_regex]] | --list";
6
+"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --list";
7
8
static char *key;
9
static regex_t *key_regexp;
@@ -190,7 +190,9 @@ int cmd_repo_config(int argc, const char **argv, const char *prefix)
190
use_key_regexp = 1;
191
do_all = 1;
192
return get_value(argv[2], argv[3]);
193
- } else if (!strcmp(argv[1], "--replace-all"))
193
+ } else if (!strcmp(argv[1], "--add"))
194
+ return git_config_set_multivar(argv[2], argv[3], "^$", 0);
195
+ else if (!strcmp(argv[1], "--replace-all"))
196
197
return git_config_set_multivar(argv[2], argv[3], NULL, 1);
198
else
t/t1300-repo-config.sh
+10
@@ -265,6 +265,16 @@ EOF
265
test_expect_success '--get-regexp' \
266
'git-repo-config --get-regexp in > output && cmp output expect'
267
268
+git-repo-config --add nextsection.nonewline "wow4 for you"
269
+
270
+cat > expect << EOF
271
+wow2 for me
272
+wow4 for you
273
+EOF
274
+
275
+test_expect_success '--add' \
276
+ 'git-repo-config --get-all nextsection.nonewline > output && cmp output expect'
277
+
278
cat > .git/config << EOF
279
[novalue]
280
variable