summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2011-01-19 12:42:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-01-21 22:31:24 (GMT)
commit4868b2ea17b7a5e8171cb109423a25a269bfefe5 (patch)
treec5d2d33f63bdd432d8424869642d93401e74786c /setup.c
parent786dabecd4766bfda0083491ef543e3b5d1d9f39 (diff)
downloadgit-4868b2ea17b7a5e8171cb109423a25a269bfefe5.zip
git-4868b2ea17b7a5e8171cb109423a25a269bfefe5.tar.gz
git-4868b2ea17b7a5e8171cb109423a25a269bfefe5.tar.bz2
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 <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/setup.c b/setup.c
index 3d73269..dadc666 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) {