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

Overriding ~/.gitconfig using GIT_CONFIG

From
RPRichard Purdie <rpurdie@rpsys.net>
Date
Aug 12, 2011, 15:38 UTC
Message-ID
<1313163498.14274.505.camel@rex>

I work on build systems which need to check code out of source control systems like git. I need to do this in a way in which there are not outside influences and a user's $HOME/.gitconfig file can contain things we don't want. I therefore need a way to disable it.

Looking through the manuals/code, it suggests I should be able to do:
GIT_CONFIG=/dev/null git XXX

and all should work happily. It doesn't though. As an example, with a ~/.gitconfig, "GIT_CONFIG=/dev/null git fetch --all" is clearly accessing the file in ~ and then acting upon it.

I've searched through the code and whilst config_exclusive_filename appears to be the magic variable that should get set when I set GIT_CONFIG in the environment, nothing ever sets it apart from within a git-config command.

The following patch sets the variable from the environment initially and should do what the code intends if I read understand it correctly. Its not ideal for my use case as I actually want the repo_config and only the repo config to be used but I can live with setting GIT_CONFIG to point at it.

Alternative ideas welcome, I've considered changing $HOME but that seems a little too ugly and likely to cause other problems.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
diff --git a/config.c b/config.c
index d06fb19..19e7565 100644
--- a/config.c
+++ b/config.c
@@ -860,6 +860,8 @@ int git_config_early(config_fn_t fn, void *data, const char *repo_config)
 	int ret = 0, found = 0;
 	const char *home = NULL;
 
+	config_exclusive_filename = getenv(CONFIG_ENVIRONMENT);
+
 	/* Setting $GIT_CONFIG makes git read _only_ the given config file. */
 	if (config_exclusive_filename)
 		return git_config_from_file(fn, config_exclusive_filename, data);
-- 
Linux Foundation
http://www.yoctoproject.org/
Next: Junio C Hamano
Message 1 of 12 in “Overriding ~/.gitconfig using GIT_CONFIG”
  1. Richard PurdieAug 12, 2011
  2. Junio C HamanoAug 12, 2011
  3. Junio C HamanoAug 12, 2011
  4. Richard PurdieAug 12, 2011
  5. David AguilarAug 28, 2011
  6. Richard PurdieAug 29, 2011
  7. David AguilarAug 30, 2011
  8. Richard PurdieAug 30, 2011
  9. Jeff KingAug 30, 2011
  10. Richard PurdieAug 30, 2011
  11. Jeff KingAug 30, 2011
  12. Richard PurdieSep 5, 2011

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.