DORMANTno replies

[PATCH v2] setup.c: set workdir when gitdir is not default

From: Max Kirillov <hidden>
Date: 2016-06-15 23:02:26
Subsystem: the rest · Maintainer: Linus Torvalds

When gitfile is used, git sets GIT_DIR environment variable for
subsequent commands, and that commands start working in mode "GIT_DIR
set, workdir current", which is incorrect for the case when git runs
from subdirectory of repository. This can be observed at least for
running aliases - git fails with message "internal error: work tree has
already been set"

Fix by setting GIT_WORK_TREE environment also.

Add test which demonstrates problem with alias.

Signed-off-by: Max Kirillov <redacted>
---
 setup.c            | 4 +++-
 t/t0002-gitfile.sh | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/setup.c b/setup.c
index 0a22f8b..bcf4e31 100644
--- a/setup.c
+++ b/setup.c
@@ -508,8 +508,10 @@ static const char *setup_discovered_git_dir(const char *gitdir,
 
 	/* #0, #1, #5, #8, #9, #12, #13 */
 	set_git_work_tree(".");
-	if (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT))
+	if (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT)) {
 		set_git_dir(gitdir);
+		setenv(GIT_WORK_TREE_ENVIRONMENT, get_git_work_tree(), 1);
+	}
 	inside_git_dir = 0;
 	inside_work_tree = 1;
 	if (offset == len)
diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
index 37e9396..64d59c3 100755
--- a/t/t0002-gitfile.sh
+++ b/t/t0002-gitfile.sh
@@ -99,4 +99,13 @@ test_expect_success 'check rev-list' '
 	test "$SHA" = "$(git rev-list HEAD)"
 '
 
+test_expect_success 'check alias call from subdirectory' '
+	test_config alias.testalias "rev-parse HEAD" &&
+	mkdir -p subdir &&
+	(
+		cd subdir &&
+		git testalias
+	)
+'
+
 test_done
-- 
2.0.1.1697.g73c6810
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help