Skip to content

Teach `--default` to `git-config(1)`

Taylor Blau git 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest3 patches 2 repliesIn review
  2. v53 patches 8 repliesSuperseded
  3. v43 patches 12 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v3 posting 2/23 patches8 repliesSuperseded
v3 posting 1/20 of 4 patches1 replySuperseded
v24 patches7 repliesSuperseded
v14 patches8 repliesSuperseded

Patches in v6 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3builtin/config: introduce `--default`Documentation/git-config.txt builtin/config.c t/t1310-config-default.sh+58 -01 reply
2/3config.c: introduce 'git_config_color' to parse ANSI colorsconfig.c config.h+11 -00 replies
3/3builtin/config: introduce `color` type specifierDocumentation/git-config.txt builtin/config.c t/t1300-repo-config.sh+58 -00 replies
3/3builtin/config: introduce `color` type specifierDocumentation/git-config.txt builtin/config.c t/t1300-repo-config.sh+58 -01 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v6 yet.

Read the v6 thread

Cover letter [PATCH v6 0/3] Teach `--default` to `git-config(1)`

Hi,

Attached is the sixth re-roll of my series to add '--type=color' as a valid option to 'git-config(1)'.

I have changed the following since v5 (an inter-diff is available below for easier consumption):

- Update prose in Documentation/git-config.txt to match Eric's suggestions.

- Remove extraneous braces, newlines from builtin/config.c. (cc:

    Eric).

- Rename, reorder tests in t1310 to make clear which tests are duals of one another. Use '-c' to introduce short-lived configuration values. (cc: Eric).

Thanks,
Taylor

Taylor Blau (3):
builtin/config: introduce --default
config.c: introduce 'git_config_color' to parse ANSI colors builtin/config: introduce color type specifier

 Documentation/git-config.txt | 10 +++++++++
 builtin/config.c             | 40 ++++++++++++++++++++++++++++++++++++
 config.c                     | 10 +++++++++
 config.h                     |  1 +
 t/t1300-repo-config.sh       | 30 +++++++++++++++++++++++++++
 t/t1310-config-default.sh    | 36 ++++++++++++++++++++++++++++++++
 6 files changed, 127 insertions(+)
 create mode 100755 t/t1310-config-default.sh

Inter-diff (since v5):

Documentation/git-config.txt +5 -6
index 05a555b568..7c8365e377 100644
@@ -177,10 +177,10 @@ Valid `<type>`'s include:
   ~/` from the command line to let your shell do the expansion.)
 - 'expiry-date': canonicalize by converting from a fixed or relative date-string
   to a timestamp. This specifier has no effect when setting the value.
-- 'color': When writing to a caller, canonicalize by converting to an ANSI color
-  escape sequence. When writing to the configuration file, a sanity-check is
-  performed to ensure that the given value is canonicalize-able as an ANSI
-  color, but it is written as-is.
+- 'color': When getting a value, canonicalize by converting to an ANSI color
+  escape sequence. When setting a value, a sanity-check is performed to ensure
+  that the given value is canonicalize-able as an ANSI color, but it is written
+  as-is.
 +
 
 --bool::
@@ -233,8 +233,7 @@ Valid `<type>`'s include:
 	output.  The optional `default` parameter is used instead, if
 	there is no color configured for `name`.
 +
-It is preferred to use `--type=color`, or `--type=color [--default=<default>]`
-instead of `--get-color`.
+`--type=color [--default=<default>]` is preferred over `--get-color`.
 
 -e::
 --edit::
builtin/config.c +4 -4
index 0c7cfcf6c9..08016863ac 100644
@@ -300,9 +300,9 @@ static int get_value(const char *key_, const char *regex_)
 		ALLOC_GROW(values.items, values.nr + 1, values.alloc);
 		item = &values.items[values.nr++];
 		strbuf_init(item, 0);
-		if (format_config(item, key_, default_value) < 0) {
-			die(_("failed to format default config value"));
-		}
+		if (format_config(item, key_, default_value) < 0)
+			die(_("failed to format default config value: %s"),
+				default_value);
 	}
 
 	ret = !values.nr;
@@ -657,7 +657,6 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
 
-
 	if (default_value && !(actions & ACTION_GET)) {
 		error("--default is only applicable to --get");
 		usage_with_options(builtin_config_usage,
@@ -814,3 +813,4 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	}
 
 	return 0;
+}
t/t1310-config-default.sh +8 -11
index b74c932763..6049d91708 100755
@@ -4,23 +4,21 @@ test_description='Test git config in different settings (with --default)'
 
 . ./test-lib.sh
 
-test_expect_success 'uses --default when missing entry' '
+test_expect_success 'uses --default when entry missing' '
 	echo quux >expect &&
-	git config -f config --default quux core.foo >actual &&
+	git config -f config --default=quux core.foo >actual &&
 	test_cmp expect actual
 '
 
-test_expect_success 'canonicalizes --default with appropriate type' '
-	echo true >expect &&
-	git config -f config --default=true --bool core.foo >actual &&
+test_expect_success 'does not use --default when entry present' '
+	echo bar >expect &&
+	git -c core.foo=bar config --default=baz core.foo >actual &&
 	test_cmp expect actual
 '
 
-test_expect_success 'uses entry when available' '
-	echo bar >expect &&
-	git config --add core.foo bar &&
-	git config --default baz core.foo >actual &&
-	git config --unset core.foo &&
+test_expect_success 'canonicalizes --default with appropriate type' '
+	echo true >expect &&
+	git config -f config --default=yes --bool core.foo >actual &&
 	test_cmp expect actual
 '
--

2.17.0