git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: David Aguilar <davvid@gmail.com>,
	Anurag Priyam <anurag08priyam@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig
Date: Thu, 27 Sep 2012 20:16:11 +0530	[thread overview]
Message-ID: <1348757171-3223-1-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <CALkWK0nYnyaoOsH_x8U96ADZT7VuP-pR36+RRcjTw39Kp1qCnw@mail.gmail.com>


Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 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

  reply	other threads:[~2012-09-27 14:46 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-26 14:14 Configuring the location of ~/.gitconfig Ramkumar Ramachandra
2012-09-26 18:34 ` David Aguilar
2012-09-27  6:49   ` Ramkumar Ramachandra
2012-09-27 14:46     ` Ramkumar Ramachandra [this message]
2012-09-27 16:57       ` [PATCH] config: introduce GIT_GLOBAL_CONFIG to override ~/.gitconfig Matthieu Moy
2012-09-27 17:50         ` Junio C Hamano
2012-09-27 17:27       ` Junio C Hamano
2012-09-27 17:35       ` Jeff King
2012-09-27 19:57         ` Junio C Hamano
2012-09-27 20:51         ` Matthieu Moy
2012-09-28  7:05         ` Ramkumar Ramachandra
2012-09-27  6:09 ` Configuring the location of ~/.gitconfig Junio C Hamano
2012-09-27  6:40   ` Anurag Priyam
2012-09-27 17:16     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1348757171-3223-1-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=anurag08priyam@gmail.com \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).