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

Re: [PATCH 3/3] worktree: reject NULL worktree in get_worktree_git_dir()

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 13, 2026, 21:42 UTC
Message-ID
<xmqqfr632yq8.fsf@gitster.g>
In-Reply-To
<1151b5b302069b4f3414a37e3be4bdbbc7e40686.1773411586.git.phillip.wood@dunelm.org.uk>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 45 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> This removes the final dependence on "the_repository" in
> get_worktree_git_dir(). The last commit removed only caller that
> passed a NULL worktree.
>
> get_worktree_git_dir() has the following callers:
>
>  - branch.c:prepare_checked_out_branches() which loops over all
>    worktrees.
>
>  - builtin/fsck.c:cmd_fsck() which loops over all worktrees.
>
>  - builtin/receive-pack.c:update_worktree() which is called from
>    update() only when "worktree" is non-NULL.
>
>  - builtin/worktree.c:validate_no_submodules() which is called from
>    check_clean_worktree() and move_worktree(), both of which supply
>    a non-NULL worktree.
>
>  - reachable.c:add_rebase_files() which loops over all worktrees.
>
>  - revision.c:add_index_objects_to_pending() which loops over all
>    worktrees.
>
>  - worktree.c:is_current_worktree() which expects a non-NULL worktree.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  worktree.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/worktree.c b/worktree.c
> index 344ad0c031b..1ed5e8c3cd2 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -227,7 +227,7 @@ struct worktree **get_worktrees_without_reading_head(void)
>  char *get_worktree_git_dir(const struct worktree *wt)
>  {
>  	if (!wt)
> -		return xstrdup(repo_get_git_dir(the_repository));
> +		BUG("%s() called with NULL worktree", __func__);
>  	else if (!wt->id)
>  		return xstrdup(repo_get_common_dir(wt->repo));
>  	else
<worktree.h> still has
    /*
     * Return git dir of the worktree. Note that the path may be relative.
     * If wt is NULL, git dir of current worktree is returned.
     */
    char *get_worktree_git_dir(const struct worktree *wt);
which needs a matching adjustment.
Previous: Phillip WoodNext: Phillip Wood
Message 6 of 27 in “worktree: stop using "the_repository" in is_current_worktree()”
  1. 0/3 worktree: stop using "the_repository" in is_current_worktree()Phillip Wood, Mar 13, 2026
  2. 1/3 worktree: remove "the_repository" from is_current_worktree()Phillip Wood, Mar 13, 2026
  3. 2/3 worktree add: stop reading ".git/HEAD"Phillip Wood, Mar 13, 2026
  4. Junio C HamanoMar 13, 2026
  5. 3/3 worktree: reject NULL worktree in get_worktree_git_dir()Phillip Wood, Mar 13, 2026
  6. Junio C HamanoMar 13, 2026
  7. Phillip WoodMar 14, 2026
  8. 0/3 worktree: stop using "the_repository" in is_current_worktree()Phillip Wood, Mar 15, 2026
  9. 1/3 worktree: remove "the_repository" from is_current_worktree()Phillip Wood, Mar 15, 2026
  10. Patrick SteinhardtMar 16, 2026
  11. Phillip WoodMar 16, 2026
  12. Phillip WoodMar 17, 2026
  13. Shreyansh PaliwalMar 23, 2026
  14. Phillip WoodMar 23, 2026
  15. Shreyansh PaliwalMar 23, 2026
  16. 2/3 worktree add: stop reading ".git/HEAD"Phillip Wood, Mar 15, 2026
  17. Patrick SteinhardtMar 16, 2026
  18. 3/3 worktree: reject NULL worktree in get_worktree_git_dir()Phillip Wood, Mar 15, 2026
  19. Junio C HamanoMar 15, 2026
  20. 0/3 worktree: stop using "the_repository" in is_current_worktree()Phillip Wood, Mar 26, 2026
  21. 1/3 worktree: remove "the_repository" from is_current_worktree()Phillip Wood, Mar 26, 2026
  22. Junio C HamanoMar 26, 2026
  23. Phillip WoodMar 27, 2026
  24. Junio C HamanoMar 27, 2026
  25. Phillip WoodApr 2, 2026
  26. 2/3 worktree add: stop reading ".git/HEAD"Phillip Wood, Mar 26, 2026
  27. 3/3 worktree: reject NULL worktree in get_worktree_git_dir()Phillip Wood, Mar 26, 2026

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.