Configuring the location of ~/.gitconfig

6 messages, 3 authors, 2016-06-15 · open the first message on its own page

Configuring the location of ~/.gitconfig

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:54:52

Hi,

I'd like to configure the location of ~/.gitconfig through an
environment variable.  My usecase is a simple enough: I have a
repository with all my dotfiles, and I don't want to symlink
~/dotfiles/.gitconfig from $HOME after cloning it.  Does anyone else
think the feature will be useful?

A couple of similar examples:
1. The git templates directory is configurable via the
GIT_TEMPLATE_DIR variable.
2. The location of ~/.zshrc, ~/.zlogin etc is configurable via the
ZDOTDIR variable in ZSH.

Ram

Re: Configuring the location of ~/.gitconfig

From: David Aguilar <hidden>
Date: 2016-06-15 22:54:52

On Wed, Sep 26, 2012 at 7:14 AM, Ramkumar Ramachandra
[off-list ref] wrote:
Hi,

I'd like to configure the location of ~/.gitconfig through an
environment variable.  My usecase is a simple enough: I have a
repository with all my dotfiles, and I don't want to symlink
~/dotfiles/.gitconfig from $HOME after cloning it.  Does anyone else
think the feature will be useful?

A couple of similar examples:
1. The git templates directory is configurable via the
GIT_TEMPLATE_DIR variable.
2. The location of ~/.zshrc, ~/.zlogin etc is configurable via the
ZDOTDIR variable in ZSH.
There was some work recently to teach git about the XDG_CONFIG_HOME variable.

Would that help, or are the XDG variables too global for your usage?
-- 
David

Re: Configuring the location of ~/.gitconfig

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:54:52

Hi David,

David Aguilar wrote:
Would that help, or are the XDG variables too global for your usage?
Yeah, they're too global.  I'll write a patch.

Ram

[PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:54:52

Signed-off-by: Ramkumar Ramachandra <redacted>
---
 Documentation/git-config.txt |    3 +++
 path.c                       |    5 +++++
 t/t1306-xdg-files.sh         |    8 ++++++++
 3 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index eaea079..c8db03f 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -205,6 +205,9 @@ $GIT_DIR/config::
 	User-specific configuration file. Also called "global"
 	configuration file.
 
+$GIT_GLOBAL_CONFIG::
+	Overrides the path of the global configuration file.
+
 $XDG_CONFIG_HOME/git/config::
 	Second user-specific configuration file. If $XDG_CONFIG_HOME is not set
 	or empty, $HOME/.config/git/config will be used. Any single-valued
diff --git a/path.c b/path.c
index cbbdf7d..9b09cee 100644
--- a/path.c
+++ b/path.c
@@ -131,10 +131,15 @@ char *git_path(const char *fmt, ...)
 
 void home_config_paths(char **global, char **xdg, char *file)
 {
+	char *global_config = getenv("GIT_GLOBAL_CONFIG");
 	char *xdg_home = getenv("XDG_CONFIG_HOME");
 	char *home = getenv("HOME");
 	char *to_free = NULL;
 
+	if (global_config) {
+		*global = mkpathdup("%s", global_config);
+		return;
+	}
 	if (!home) {
 		if (global)
 			*global = NULL;
diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh
index 8b14ab1..5b0e08e 100755
--- a/t/t1306-xdg-files.sh
+++ b/t/t1306-xdg-files.sh
@@ -28,6 +28,14 @@ test_expect_success 'read config: xdg file exists and ~/.gitconfig exists' '
 	test_cmp expected actual
 '
 
+test_expect_success 'read config: $GIT_GLOBAL_CONFIG is set and ~/.gitconfig exists' '
+	>.gitconfig &&
+	echo "[alias]" >.gittestconfig &&
+	echo "	myalias = !echo in_gitconfig" >>.gittestconfig &&
+	echo in_gitconfig >expected &&
+	GIT_GLOBAL_CONFIG=~/.gittestconfig git myalias >actual &&
+	test_cmp expected actual
+'
 
 test_expect_success 'read with --get: xdg file exists and ~/.gitconfig doesn'\''t' '
 	rm .gitconfig &&
-- 
1.7.8.1.362.g5d6df.dirty

Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig

From: Jeff King <hidden>
Date: 2016-06-15 22:54:53

On Thu, Sep 27, 2012 at 08:16:11PM +0530, Ramkumar Ramachandra wrote:
quoted hunk
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index eaea079..c8db03f 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -205,6 +205,9 @@ $GIT_DIR/config::
 	User-specific configuration file. Also called "global"
 	configuration file.
 
+$GIT_GLOBAL_CONFIG::
+	Overrides the path of the global configuration file.
+
Like the other reviews, I am not overly enthused. If we are going to add
a new variable, I think $GIT_HOME makes a lot more sense. But it really
sounds like using $XDG_CONFIG_HOME would be even simpler.

Also, have you considered using a config include? Like:

  $ echo '[include]path = ~/my-dotfiles/gitconfig' >~/.gitconfig

It's a one-time setup, and then you get updates inside my-dotfiles
forever. The one-time setup is annoying, but you have to bootstrap
somehow (e.g., you're going to have to copy a .profile or similar to get
the GIT_GLOBAL_CONFIG variable set).

-Peff

Re: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig

From: Ramkumar Ramachandra <hidden>
Date: 2016-06-15 22:54:53

Jeff King wrote:
Like the other reviews, I am not overly enthused. If we are going to add
a new variable, I think $GIT_HOME makes a lot more sense. But it really
sounds like using $XDG_CONFIG_HOME would be even simpler.

Also, have you considered using a config include? Like:

  $ echo '[include]path = ~/my-dotfiles/gitconfig' >~/.gitconfig
Sounds like this is the way to go.  Or I could pick up Junio's
suggestion to use a Makefile.  I'll discontinue working on the patch.

Thanks.

Ram
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help