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

Re: [PATCH] init: don't set core.worktree when initializing /.git

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 31, 2015, 19:14 UTC
Message-ID
<20150331191420.GE22844@google.com>
In-Reply-To
<20150331183423.GD19206@peff.net>
Jeff King wrote:
> No tests, as we would need to be able to write to "/" to do
> so.

t1509-root-worktree.sh is supposed to test the repository-at-/ case. But I wouldn't be surprised if it's bitrotted, since people don't set up a throwaway chroot or VM for tests too often.

[...]
Show 5 quoted lines
> The current behavior isn't _wrong_, in the sense that it's OK to set
> core.worktree when we don't need to. But I think it is unnecessarily
> confusing to users who expect to be able to move .git directories
> around, because it usually just works. So I'd call this an extremely
> minor bug.
This belongs in the commit message.
[...]
Show 13 quoted lines
> --- a/builtin/init-db.c
> +++ b/builtin/init-db.c
> @@ -182,6 +182,21 @@ static int git_init_db_config(const char *k, const char *v, void *cb)
>  	return 0;
>  }
>  
> +/*
> + * If the git_dir is not directly inside the working tree, then git will not
> + * find it by default, and we need to set the worktree explicitly.
> + */
> +static int needs_work_tree_config(const char *git_dir, const char *work_tree)
> +{
> +	/* special case that is missed by the general rule below */

(optional) I'd leave out this comment --- it seems obvious enough in context and the purpose of the comment is unobvious without looking at the history.

Show 5 quoted lines
> +	if (!strcmp(work_tree, "/") && !strcmp(git_dir, "/.git"))
> +		return 0;
> +	if (skip_prefix(git_dir, work_tree, &git_dir) &&
> +	    !strcmp(git_dir, "/.git"))
> +		return 0;

work_tree has been cleaned up with real_path, so in the normal case it contains getcwd() output which will not end with a / unless it has to. The only exception I can see is when git hits the MAXDEPTH limit for symlink resolution (5 nested symlinks), in which case we take what we find instead of erroring out, which looks like a bug.

We have called set_git_dir_init so git_dir has been cleaned up by real_path in the same way. Good.

With or without the commit message, comment, and test improvements
mentioned above,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Thanks.
Previous: Jeff KingNext: Jeff King
Message 4 of 11 in “Forcing git top-level”
  1. Cedric GavaMar 31, 2015
  2. Jeff KingMar 31, 2015
  3. init: don't set core.worktree when initializing /.gitJeff King, Mar 31, 2015
  4. Jonathan NiederMar 31, 2015
  5. init: don't set core.worktree when initializing /.gitJeff King, Apr 2, 2015
  6. Jonathan NiederApr 2, 2015
  7. t1509: update prepare script to be able to run t1509 in chroot againNguyễn Thái Ngọc Duy, Apr 3, 2015
  8. Jeff KingApr 3, 2015
  9. Duy NguyenApr 3, 2015
  10. Junio C HamanoApr 11, 2015
  11. t1509: update prepare script to be able to run t1509 in chroot againNguyễn Thái Ngọc Duy, Apr 18, 2015

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.