]> Kevux Git Server - rit/commitdiff
worktree: reject NULL worktree in get_worktree_git_dir()
authorPhillip Wood <phillip.wood@dunelm.org.uk>
Thu, 26 Mar 2026 14:16:59 +0000 (14:16 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2026 15:20:50 +0000 (08:20 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
worktree.c
worktree.h

index 344ad0c031bf1ff3f6eb12d1aa475e87ba8bd484..1ed5e8c3cd27a149978cacee88e3db604fedef0f 100644 (file)
@@ -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
index 94ae58db973ec465ebcedc20839fd78f977853f5..400b614f133650d0bdfc561c44bb8305fe04f2e9 100644 (file)
@@ -51,7 +51,6 @@ int submodule_uses_worktrees(const char *path);
 
 /*
  * 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);