[PATCH] Introduce the GIT_CONFIG_EXTRA environment variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is like GIT_CONFIG but it is not read instead of .git/config, but
in addtition to it.

Signed-off-by: Miklos Vajna <vmiklos@xxxxxxxxxxxxxx>
---

On Fri, Dec 18, 2009 at 11:54:32PM +0100, Moe <moe@xxxxxxxxxxxxxx> wrote:
> $GIT_CONFIG doesn't work for this purpose because when set
> git will *only* read the referenced file and ignore the
> repository settings.

What about this?

 Documentation/git-config.txt |    3 +++
 builtin-config.c             |    7 ++++++-
 config.c                     |    9 ++++++++-
 t/t1300-repo-config.sh       |   16 ++++++++++++++++
 4 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index f68b198..668db3f 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -211,6 +211,9 @@ GIT_CONFIG::
 	Using the "--global" option forces this to ~/.gitconfig. Using the
 	"--system" option forces this to $(prefix)/etc/gitconfig.
 
+GIT_CONFIG_EXTRA::
+	Take the configuration from the given file in addition to .git/config.
+
 See also <<FILES>>.
 
 
diff --git a/builtin-config.c b/builtin-config.c
index a2d656e..4a702f6 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -142,7 +142,7 @@ static int get_value(const char *key_, const char *regex_)
 	int ret = -1;
 	char *tl;
 	char *global = NULL, *repo_config = NULL;
-	const char *system_wide = NULL, *local;
+	const char *system_wide = NULL, *local, *extra = NULL;
 
 	local = config_exclusive_filename;
 	if (!local) {
@@ -152,6 +152,7 @@ static int get_value(const char *key_, const char *regex_)
 			global = xstrdup(mkpath("%s/.gitconfig", home));
 		if (git_config_system())
 			system_wide = git_etc_gitconfig();
+		extra = getenv("GIT_CONFIG_EXTRA");
 	}
 
 	key = xstrdup(key_);
@@ -185,11 +186,15 @@ static int get_value(const char *key_, const char *regex_)
 		git_config_from_file(show_config, system_wide, NULL);
 	if (do_all && global)
 		git_config_from_file(show_config, global, NULL);
+	if (do_all && extra)
+		git_config_from_file(show_config, extra, NULL);
 	git_config_from_file(show_config, local, NULL);
 	if (!do_all && !seen && global)
 		git_config_from_file(show_config, global, NULL);
 	if (!do_all && !seen && system_wide)
 		git_config_from_file(show_config, system_wide, NULL);
+	if (!do_all && !seen && extra)
+		git_config_from_file(show_config, extra, NULL);
 
 	free(key);
 	if (regexp) {
diff --git a/config.c b/config.c
index 37385ce..cf816ed 100644
--- a/config.c
+++ b/config.c
@@ -700,7 +700,7 @@ int git_config(config_fn_t fn, void *data)
 {
 	int ret = 0, found = 0;
 	char *repo_config = NULL;
-	const char *home = NULL;
+	const char *home = NULL, *extra = NULL;
 
 	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
 	if (config_exclusive_filename)
@@ -727,6 +727,13 @@ int git_config(config_fn_t fn, void *data)
 		found += 1;
 	}
 	free(repo_config);
+
+	extra = getenv("GIT_CONFIG_EXTRA");
+	if (extra && !access(extra, R_OK)) {
+		ret += git_config_from_file(fn, extra, data);
+		found += 1;
+	}
+
 	if (found == 0)
 		return -1;
 	return ret;
diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh
index 83b7294..ed7fcb6 100755
--- a/t/t1300-repo-config.sh
+++ b/t/t1300-repo-config.sh
@@ -398,6 +398,22 @@ test_expect_success 'alternative GIT_CONFIG' 'cmp output expect'
 test_expect_success 'alternative GIT_CONFIG (--file)' \
 	'git config --file other-config -l > output && cmp output expect'
 
+cat > extra-config <<EOF
+[extra]
+	config = value
+EOF
+
+cat > expect << EOF
+c
+value
+EOF
+
+test_expect_success 'additional GIT_CONFIG_EXTRA' '
+	GIT_CONFIG_EXTRA=extra-config git config a.b > output &&
+	GIT_CONFIG_EXTRA=extra-config git config extra.config >> output &&
+	cmp output expect
+'
+
 GIT_CONFIG=other-config git config anwohner.park ausweis
 
 cat > expect << EOF
-- 
1.6.5.2

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]