Subject: [PATCH 1/7] setup: support setting GIT_DIR=.git file

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Wed, 27 Oct 2010 21:58:10 +0700

---
 setup.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/setup.c b/setup.c
index a3b76de..2e7387d 100644
--- a/setup.c
+++ b/setup.c
@@ -317,17 +317,20 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
 				const char *work_tree_env, int *nongit_ok)
 {
 	static char buffer[1024 + 1];
-	const char *retval;
+	const char *retval, *gitfile;
 
 	if (PATH_MAX - 40 < strlen(gitdirenv))
 		die("'$%s' too big", GIT_DIR_ENVIRONMENT);
-	if (!is_git_directory(gitdirenv)) {
+	gitfile = read_gitfile_gently(gitdirenv);
+	if (!gitfile && !is_git_directory(gitdirenv)) {
 		if (nongit_ok) {
 			*nongit_ok = 1;
 			return NULL;
 		}
 		die("Not a git repository: '%s'", gitdirenv);
 	}
+	if (gitfile)
+		set_git_dir(gitfile);
 	if (!work_tree_env) {
 		retval = set_work_tree(gitdirenv);
 		/* config may override worktree */
@@ -341,7 +344,8 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
 			get_git_work_tree());
 	if (!retval || !*retval)
 		return NULL;
-	set_git_dir(make_absolute_path(gitdirenv));
+	if (!gitfile)
+		set_git_dir(make_absolute_path(gitdirenv));
 	if (chdir(work_tree_env) < 0)
 		die_errno ("Could not chdir to '%s'", work_tree_env);
 	strcat(buffer, "/");
-- 
1.7.0.2.445.gcbdb3