]> git.ipfire.org Git - thirdparty/git.git/commit - worktree.c
worktree: skip reading HEAD when repairing worktrees
authorPatrick Steinhardt <ps@pks.im>
Fri, 29 Dec 2023 07:26:30 +0000 (08:26 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Jan 2024 17:24:47 +0000 (09:24 -0800)
commit465a22b338a05a5ffeeffc6bd9174ef5d9a090a0
treed8e45cd3b7527569fae8eb9d864c07d533424dec
parentbb0372c9799915fc3e6c2cf8e17815ce22622acd
worktree: skip reading HEAD when repairing worktrees

When calling `git init --separate-git-dir=<new-path>` on a preexisting
repository, we move the Git directory of that repository to the new path
specified by the user. If there are worktrees present in the repository,
we need to repair the worktrees so that their gitlinks point to the new
location of the repository.

This repair logic will load repositories via `get_worktrees()`, which
will enumerate up and initialize all worktrees. Part of initialization
is logic that we resolve their respective worktree HEADs, even though
that information may not actually be needed in the end by all callers.

Although not a problem presently with the file-based reference backend,
it will become a problem with the upcoming reftable backend. In the
context of git-init(1) we do not have a fully-initialized repository set
up via `setup_git_directory()` or friends. Consequently, we do not know
about the repository format when `repair_worktrees()` is called, and
properly setting up all parts of the repositroy in `init_db()` before we
try to repair worktrees is not an easy task. With the introduction of
the reftable backend, we would ultimately try to look up the worktree
HEADs before we have figured out the reference format, which does not
work.

We do not require the worktree HEADs at all to repair worktrees. So
let's fix this issue by skipping over the step that reads them.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
worktree.c