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@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html