git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] setup_git_directory: Setup cwd properly if worktree is found

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Nov 12, 2007, 11:57 UTC
Message-ID
<Pine.LNX.4.64.0711121139010.4362@racer.site>
In-Reply-To
<20071112112408.GA5420@laptop>
Hi,
On Mon, 12 Nov 2007, Nguyễn Thái Ngọc Duy wrote:
Show 15 quoted lines
> 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.

Previous: Nguyễn Thái Ngọc DuyNext: Johannes Sixt
Message 2 of 6 in “setup_git_directory: Setup cwd properly if worktree is found”
  1. setup_git_directory: Setup cwd properly if worktree is foundNguyễn Thái Ngọc Duy, Nov 12, 2007
  2. Johannes SchindelinNov 12, 2007
  3. Johannes SixtNov 12, 2007
  4. Johannes SchindelinNov 12, 2007
  5. Nguyen Thai Ngoc DuyNov 27, 2007
  6. Johannes SchindelinNov 27, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.