Skip to content

Commit 7580868

Browse files
phillipwoodgitster
authored andcommitted
worktree: reject NULL worktree in get_worktree_git_dir()
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>
1 parent 8bad0e0 commit 7580868

2 files changed

Lines changed: 1 addition & 2 deletions

File tree

worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ struct worktree **get_worktrees_without_reading_head(void)
227227
char *get_worktree_git_dir(const struct worktree *wt)
228228
{
229229
if (!wt)
230-
return xstrdup(repo_get_git_dir(the_repository));
230+
BUG("%s() called with NULL worktree", __func__);
231231
else if (!wt->id)
232232
return xstrdup(repo_get_common_dir(wt->repo));
233233
else

worktree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ int submodule_uses_worktrees(const char *path);
5151

5252
/*
5353
* Return git dir of the worktree. Note that the path may be relative.
54-
* If wt is NULL, git dir of current worktree is returned.
5554
*/
5655
char *get_worktree_git_dir(const struct worktree *wt);
5756

0 commit comments

Comments
 (0)