]> git.ipfire.org Git - thirdparty/git.git/commit
builtin/init: stop modifying global `git_work_tree_cfg` variable
authorPatrick Steinhardt <ps@pks.im>
Thu, 11 Jun 2026 06:44:39 +0000 (08:44 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Jun 2026 12:05:54 +0000 (05:05 -0700)
commit9bef2cf33111dc844e46a8a19c266320774f4bd6
treec17a01a2170c50d43b20fe7d1a749e29b61bcd3c
parent36bafa0b6582e0968d33d48cf3a1eaa29ceb6661
builtin/init: stop modifying global `git_work_tree_cfg` variable

When executing git-init(1) we need to figure out the final location of
the worktree. This location can be configured in a couple of ways: via
an environment variable, via the preexisting "core.worktree" config in
case we're reinitializing, or implicitly when reinitializing a non-bare
repository.

When checking for the worktree location in "builtin/init-db.c" we
populate any potentially-discovered value both by setting the global
`git_work_tree_cfg` variable and via `set_git_work_tree()`, which
ultimately ends up modifying `struct repository::worktree`.

Modifying `git_work_tree_cfg` is unnecessary though: we configure the
worktree in `create_default_files()`, and that function derives the
worktree location via `repo_get_work_tree()`. Consequently, propagating
the worktree via `set_git_work_tree()` is sufficient.

Stop munging `git_work_tree_cfg` and make it file-local to "setup.c" and
function-local to `cmd_init_db()`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/init-db.c
environment.c
environment.h
setup.c