From 4868b2ea17b7a5e8171cb109423a25a269bfefe5 Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Wed, 19 Jan 2011 06:42:30 -0600 Subject: Subject: setup: officially support --work-tree without --git-dir The original intention of --work-tree was to allow people to work in a subdirectory of their working tree that does not have an embedded .git directory. Because their working tree, which their $cwd was in, did not have an embedded .git, they needed to use $GIT_DIR to specify where it is, and because this meant there was no way to discover where the root level of the working tree was, so we needed to add $GIT_WORK_TREE to tell git where it was. However, this facility has long been (mis)used by people's scripts to start git from a working tree _with_ an embedded .git directory, let git find .git directory, and then pretend as if an unrelated directory were the associated working tree of the .git directory found by the discovery process. It happens to work in simple cases, and is not worth causing "regression" to these scripts. Signed-off-by: Jonathan Nieder Signed-off-by: Junio C Hamano --- setup.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'setup.c') diff --git a/setup.c b/setup.c index 3d732697af..dadc66659a 100644 --- a/setup.c +++ b/setup.c @@ -411,6 +411,15 @@ static const char *setup_discovered_git_dir(const char *gitdir, if (check_repository_format_gently(gitdir, nongit_ok)) return NULL; + /* --work-tree is set without --git-dir; use discovered one */ + if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) { + if (offset != len && !is_absolute_path(gitdir)) + gitdir = xstrdup(make_absolute_path(gitdir)); + if (chdir(cwd)) + die_errno("Could not come back to cwd"); + return setup_explicit_git_dir(gitdir, cwd, len, nongit_ok); + } + /* #16.2, #17.2, #20.2, #21.2, #24, #25, #28, #29 (see t1510) */ if (is_bare_repository_cfg > 0) { set_git_dir(offset == len ? gitdir : make_absolute_path(gitdir)); @@ -443,6 +452,16 @@ static const char *setup_bare_git_dir(char *cwd, int offset, int len, int *nongi if (check_repository_format_gently(".", nongit_ok)) return NULL; + /* --work-tree is set without --git-dir; use discovered one */ + if (getenv(GIT_WORK_TREE_ENVIRONMENT) || git_work_tree_cfg) { + const char *gitdir; + + gitdir = offset == len ? "." : xmemdupz(cwd, offset); + if (chdir(cwd)) + die_errno("Could not come back to cwd"); + return setup_explicit_git_dir(gitdir, cwd, len, nongit_ok); + } + inside_git_dir = 1; inside_work_tree = 0; if (offset != len) { -- cgit v1.2.3