[PATCH v3 3/3] worktree: reject NULL worktree in get_worktree_git_dir()
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Mar 26, 2026, 14:16 UTC
- Message-ID
- <c3329028010269995008d92653ba6dc4a5322118.1774534617.git.phillip.wood@dunelm.org.uk>
- In-Reply-To
- <cover.1774534617.git.phillip.wood@dunelm.org.uk>
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 +- worktree.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
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 diff --git a/worktree.h b/worktree.h index 94ae58db973..400b614f133 100644 --- a/worktree.h +++ b/worktree.h @@ -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);
-- 2.52.0.362.g884e03848a9.dirty