Hi, On Mon, 12 Nov 2007, Nguyễn Thái Ngọc Duy wrote: > diff --git a/setup.c b/setup.c > index 6f8f769..d90f65e 100644 > --- a/setup.c > +++ b/setup.c > @@ -360,7 +360,12 @@ const char *setup_git_directory(void) > if (retval && chdir(retval)) > die ("Could not jump back into original cwd"); > rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree()); > - return rel && *rel ? strcat(rel, "/") : NULL; > + if (rel && *rel) { > + if (chdir(get_git_work_tree())) > + die ("Could not chdir to %s", get_git_work_tree()); > + return strcat(rel, "/"); > + } > + return NULL; Hmm. Maybe this needs a bit more clarification? When setup_git_directory() returns, the cwd is supposed to be the current working tree's root. Your patch fixes that nicely when the worktree setting was overridden by the config (which is read in check_repository_format()). But what about setup_git_directory_gently()? If the working tree is overridden by the config, this function is still bogus, right? As far as I see, setup_git_directory_gently() only works correctly when core.worktree is _not_ set, unless GIT_WORK_TREE is set (which is supposed to override the config setting). Note: I treat GIT_WORK_TREE the same as --work-tree, since at that time they are identical. Maybe the config stuff has to move into _gently()? Ciao, Dscho P.S.: Thanks for picking up the ball. At some stage I got so fed up with the work-tree stuff that I had to take a long break from it. It is a messy concept, and the implementation is messy, partly because of it, and partly because I wrote it.