From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] setup_explicit_git_dir: adjust relative $GIT_WORK_TREE after moving cwd
Date: Sun, 26 Dec 2010 18:46:54 +0700 [thread overview]
Message-ID: <1293364014-8463-2-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1293364014-8463-1-git-send-email-pclouds@gmail.com>
setup_explicit_git_dir() can move cwd. If $GIT_WORK_TREE is relative
to original cwd, then the subsequent git processes will take wrong
worktree.
Instead of making $GIT_WORK_TREE absolute too, we just say "." and let
subsequent git processes handle it.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
This one is on top of nd/setup. If nd/setup does not make it in the
next release, I can still make similar patch for master, but I don't
think this happens in real life, therefore not really urgent to fix.
There are only few cases where git spawns more git processes.
For those that do that, setup_work_tree() is likely called by git.c
already, which is what the first patch is for.
setup.c | 7 +++++++
t/t1501-worktree.sh | 12 ++++++++++++
2 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/setup.c b/setup.c
index 3d73269..10b8f16 100644
--- a/setup.c
+++ b/setup.c
@@ -392,6 +392,13 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
set_git_dir(make_absolute_path(gitdirenv));
if (chdir(worktree))
die_errno("Could not chdir to '%s'", worktree);
+ /*
+ * Make sure subsequent git processes find correct worktree
+ * if $GIT_WORK_TREE is set relative
+ */
+ if (work_tree_env)
+ setenv(GIT_WORK_TREE_ENVIRONMENT, ".", 1);
+
cwd[len++] = '/';
cwd[len] = '\0';
free(gitfile);
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index 1f3b50d..fa35c3e 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -351,4 +351,16 @@ test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' '
)
'
+test_expect_success 'relative $GIT_WORK_TREE and git subprocesses (2)' '
+ (
+ cd repo.git/work/sub &&
+ GIT_DIR=../.. &&
+ GIT_WORK_TREE=.. &&
+ export GIT_DIR GIT_WORK_TREE &&
+ test-subprocess rev-parse --show-toplevel >actual &&
+ echo "$TRASH_DIRECTORY/repo.git/work" >expected &&
+ test_cmp expected actual
+ )
+'
+
test_done
--
1.7.3.4.878.g439c7
next prev parent reply other threads:[~2010-12-26 11:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-25 13:57 [PATCH 1/2] t1501: avoid bashisms Nguyễn Thái Ngọc Duy
2010-12-25 13:57 ` [PATCH 2/2] setup_work_tree: adjust relative $GIT_WORK_TREE after moving cwd Nguyễn Thái Ngọc Duy
2010-12-26 11:46 ` [PATCH] " Nguyễn Thái Ngọc Duy
2010-12-26 11:46 ` Nguyễn Thái Ngọc Duy [this message]
2010-12-27 1:26 ` Nguyễn Thái Ngọc Duy
2010-12-25 14:12 ` [PATCH 1/2] t1501: avoid bashisms Andreas Schwab
2010-12-25 14:29 ` Nguyen Thai Ngoc Duy
2010-12-25 14:44 ` Nguyen Thai Ngoc Duy
2010-12-26 19:23 ` 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=1293364014-8463-2-git-send-email-pclouds@gmail.com \
--to=pclouds@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.