git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Introduce the GIT_CONFIG_EXTRA environment variable

From
Miklos Vajna <vmiklos@frugalware.org>
Date
Dec 19, 2009, 01:32 UTC
Message-ID
<20091219013246.GD25474@genesis.frugalware.org>
In-Reply-To
<4B2C0828.4010505@signalbeam.net>

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@frugalware.org>
---
On Fri, Dec 18, 2009 at 11:54:32PM +0100, Moe <moe@signalbeam.net> 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
Previous: MoeNext: Shawn O. Pearce
Message 2 of 23 in “FEATURE REQUEST: Env override GIT_GLOBAL_CONFIG”
  1. MoeDec 18, 2009
  2. Introduce the GIT_CONFIG_EXTRA environment variableMiklos Vajna, Dec 19, 2009
  3. Shawn O. PearceDec 19, 2009
  4. MoeDec 19, 2009
  5. Miklos VajnaDec 19, 2009
  6. Junio C HamanoDec 19, 2009
  7. MoeDec 19, 2009
  8. Junio C HamanoDec 19, 2009
  9. MoeDec 19, 2009
  10. Johannes SchindelinDec 19, 2009
  11. MoeDec 19, 2009
  12. Nanako ShiraishiDec 19, 2009
  13. Introduce the GIT_HOME environment variableMiklos Vajna, Dec 19, 2009
  14. Michael J GruberDec 19, 2009
  15. Introduce the GIT_HOME environment variableMiklos Vajna, Dec 19, 2009
  16. Matthieu MoyDec 19, 2009
  17. Junio C HamanoDec 19, 2009
  18. Matthieu MoyDec 21, 2009
  19. Jeff KingDec 21, 2009
  20. Matthieu MoyDec 21, 2009
  21. Michael J GruberDec 21, 2009
  22. Junio C HamanoDec 19, 2009
  23. Introduce the GIT_HOME environment variableMiklos Vajna, Dec 20, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.