diff options
author | Taylor Blau <me@ttaylorr.com> | 2018-04-10 03:18:26 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2018-04-23 16:51:38 +0300 |
commit | eeaa24b9908878876abf3868d6934143f7ca08ea (patch) | |
tree | 6fbc4c8e023cb77a62d0fa85b2a2272785f35f73 /Documentation | |
parent | fb0dc3bac135e9f6243bd6d293e8c9293c73b9cd (diff) |
builtin/config: introduce `--default`
For some use cases, callers of the `git-config(1)` builtin would like to
fallback to default values when the variable asked for does not exist.
In addition, users would like to use existing type specifiers to ensure
that values are parsed correctly when they do exist in the
configuration.
For example, to fetch a value without a type specifier and fallback to
`$fallback`, the following is required:
$ git config core.foo || echo "$fallback"
This is fine for most values, but can be tricky for difficult-to-express
`$fallback`'s, like ANSI color codes.
This motivates `--get-color`, which is a one-off exception to the normal
type specifier rules wherein a user specifies both the configuration
variable and an optional fallback. Both are formatted according to their
type specifier, which eases the burden on the user to ensure that values
are correctly formatted.
This commit (and those following it in this series) aim to eventually
replace `--get-color` with a consistent alternative. By introducing
`--default`, we allow the `--get-color` action to be promoted to a
`--type=color` type specifier, retaining the "fallback" behavior via the
`--default` flag introduced in this commit.
For example, we aim to replace:
$ git config --get-color variable [default] [...]
with:
$ git config --default default --type=color variable [...]
Values filled by `--default` behave exactly as if they were present in
the affected configuration file; they will be parsed by type specifiers
without the knowledge that they are not themselves present in the
configuration.
Specifically, this means that the following will work:
$ git config --int --default 1M does.not.exist
1048576
In subsequent commits, we will offer `--type=color`, which (in
conjunction with `--default`) will be sufficient to replace
`--get-color`.
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/git-config.txt | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index b759009c75..c3adafd78a 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -240,6 +240,10 @@ Valid `<type>`'s include: using `--file`, `--global`, etc) and `on` when searching all config files. +--default <value>:: + When using `--get`, and the requested variable is not found, behave as if + <value> were the value assigned to the that variable. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when |