config: teach "git config --file -" to read from the standard input

The patch extends git config --file interface to allow read config from
stdin.

Editing stdin or setting value in stdin is an error.

Include by absolute path is allowed in stdin config, but not by relative
path.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Kirill A. Shutemov
2014-02-19 00:58:55 +02:00
committed by Junio C Hamano
parent c8985ce053
commit 3caec73b55
5 changed files with 70 additions and 18 deletions

View File

@ -360,6 +360,9 @@ static int get_colorbool(int print)
static void check_write(void)
{
if (given_config_source.use_stdin)
die("writing to stdin is not supported");
if (given_config_source.blob)
die("writing config blobs is not supported");
}
@ -472,6 +475,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)
usage_with_options(builtin_config_usage, builtin_config_options);
}
if (given_config_source.file &&
!strcmp(given_config_source.file, "-")) {
given_config_source.file = NULL;
given_config_source.use_stdin = 1;
}
if (use_global_config) {
char *user_config = NULL;
char *xdg_config = NULL;
@ -558,6 +567,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
check_argc(argc, 0, 0);
if (!given_config_source.file && nongit)
die("not in a git directory");
if (given_config_source.use_stdin)
die("editing stdin is not supported");
if (given_config_source.blob)
die("editing blobs is not supported");
git_config(git_default_config, NULL);