setup: stop using the_repository in setup_work_tree()

Stop using `the_repository` in `setup_work_tree()` and instead accept
the repository as a parameter. The injection of `the_repository` is thus
bumped one level higher, where callers now pass it in explicitly.

Note that the function tracks bogus worktree configuration via a global
variable. If we have bogus configuration, and if later on some caller
tries to setup a worktree, then we'll die instead.

Of course, tracking this as a global variable doesn't make sense anymore
now that we can set up worktrees for arbitrary repositories. Move the
variable into `struct repository` instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2026-03-30 15:17:31 +02:00
committed by Junio C Hamano
parent e282d01b4a
commit 4f924d92cd
21 changed files with 38 additions and 36 deletions

2
git.c
View File

@@ -497,7 +497,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv, struct
commit_pager_choice();
if (!help && p->option & NEED_WORK_TREE)
setup_work_tree();
setup_work_tree(the_repository);
trace_argv_printf(argv, "trace: built-in: git");
trace2_cmd_name(p->cmd);