[PATCH] Add --add option to git-repo-config

Subsystems: documentation, the rest

DORMANTno replies

3 messages, 2 authors, 2016-08-11 · open the first message on its own page

[PATCH] Add --add option to git-repo-config

From: Brian Gernhardt <hidden>
Date: 2016-08-11 20:43:21

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 so new users can find it and and a test to
make sure it works.

Signed-off-by: Brian Gernhardt <redacted>
---

Found myself wanting this so decided to code it myself instead of
just complaining.

Documentation/git-repo-config.txt |   14 +++++++++++++-
builtin-repo-config.c             |    6 ++++--
t/t1300-repo-config.sh            |   10 ++++++++++
3 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-repo-config.txt b/Documentation/git- 
repo-config.txt
index 5bede9a..b379ec5 100644
--- a/Documentation/git-repo-config.txt
+++ b/Documentation/git-repo-config.txt
@@ -10,6 +10,7 @@ SYNOPSIS
  --------
  [verse]
  'git-repo-config' [--global] [type] name [value [value_regex]]
+'git-repo-config' [--global] [type] --add name value
  'git-repo-config' [--global] [type] --replace-all name [value  
[value_regex]]
  'git-repo-config' [--global] [type] --get name [value_regex]
  '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
  actually the section and the key separated by a dot, and the value  
will be
  escaped.
-If you want to set/unset an option which can occur on multiple
+Multiple lines can be added to an option by using the '--add' option.
+If you want to update or unset an option which can occur on multiple
  lines, a POSIX regexp `value_regex` needs to be given.  Only the
  existing values that match the regexp are updated or unset.  If
  you want to handle the lines that do *not* match the regex, just
@@ -53,6 +55,10 @@ OPTIONS
  	Default behavior is to replace at most one line. This replaces
  	all lines matching the key (and optionally the value_regex).
+--add::
+	Adds a new line to the option without altering any existing
+	values.  This is the same as providing '^$' as the value_regex.
+
--get::
  	Get the value for a given key (optionally filtered by a regex
  	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
  % git repo-config section.key value '[!]'
  ------------
+To add a new proxy, without altering any of the existing ones, use
+
+------------
+% git repo-config core.gitproxy '"proxy" for example.com'
+------------
+
include::config.txt[]
diff --git a/builtin-repo-config.c b/builtin-repo-config.c
index 7b6e572..64fbdb7 100644
--- a/builtin-repo-config.c
+++ b/builtin-repo-config.c
@@ -3,7 +3,7 @@
  #include <regex.h>
  static const char git_config_set_usage[] =
-"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all  
| --get-regexp | --replace-all | --unset | --unset-all] name [value  
[value_regex]] | --list";
+"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all  
| --get-regexp | --replace-all | --add | --unset | --unset-all] name  
[value [value_regex]] | --list";
  static char *key;
  static regex_t *key_regexp;
@@ -190,7 +190,9 @@ int cmd_repo_config(int argc, const char **argv,  
const char *prefix)
  			use_key_regexp = 1;
  			do_all = 1;
  			return get_value(argv[2], argv[3]);
-		} else if (!strcmp(argv[1], "--replace-all"))
+		} else if (!strcmp(argv[1], "--add"))
+			return git_config_set_multivar(argv[2], argv[3], "^$", 0);
+		else if (!strcmp(argv[1], "--replace-all"))
  			return git_config_set_multivar(argv[2], argv[3], NULL, 1);
  		else
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 0de2497..16cd642 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -265,6 +265,16 @@ EOF
  test_expect_success '--get-regexp' \
  	'git-repo-config --get-regexp in > output && cmp output expect'
+git-repo-config --add nextsection.nonewline "wow4 for you"
+
+cat > expect << EOF
+wow2 for me
+wow4 for you
+EOF
+
+test_expect_success '--add' \
+	'git-repo-config --get-all nextsection.nonewline > output && cmp  
output expect'
+
  cat > .git/config << EOF
  [novalue]
  	variable
--
1.4.4.1.GIT

Re: [PATCH] Add --add option to git-repo-config

From: Brian Gernhardt <hidden>
Date: 2016-08-11 20:23:14

On Dec 15, 2006, at 3:54 AM, Jakub Narebski wrote:
Brian Gernhardt wrote:
quoted
  'git-repo-config' [--global] [type] name [value [value_regex]]
+'git-repo-config' [--global] [type] --add name value
In few places it seems that original has one space at beginning of  
line,
and added value lacks this space.

Otherwise, very nice patch. Thanks!
None of the originals have spaces at the beginning of the lines in my  
repo.  I think that's an artifact of Mail.app mangling whitespace at  
the beginning of the line when copy/pasting patches.  I thought it  
only happened in a couple places and tried to fix it by hand.   
Apparently that didn't work, and I need to install mutt or something  
to send things from the command line.  In the meantime, I can re-send  
the patch as an attachment, if that'll help.

Re: [PATCH] Add --add option to git-repo-config

From: Jakub Narebski <hidden>
Date: 2016-08-11 20:31:27

Brian Gernhardt wrote:
  'git-repo-config' [--global] [type] name [value [value_regex]]
+'git-repo-config' [--global] [type] --add name value
In few places it seems that original has one space at beginning of line,
and added value lacks this space.

Otherwise, very nice patch. Thanks!
-- 
Jakub Narebski
Warsaw, Poland
ShadeHawk on #git
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help