Yoichi NAKAYAMA's series says git worktree repair does not sufficiently validate the cross-references between a linked working tree and its administrative data, which can cause it to modify the wrong .git file or gitdir in some situations.

Patch 1/2 refactors the code to read the .git file once and extract the worktree ID without changing behavior. Patch 2/2 uses that information to validate the worktree ID and the inferred gitdir path before repairing the links.

In a follow-up, Yoichi noted that infer_backlink() accepts the "gitdir:" prefix without requiring a following space and uses strbuf_trim(), which does more than strip trailing newlines. That is more lenient than read_gitfile_gently(), which other Git commands use.

He wrote that the main purpose of worktree repair is to fix problems such as relocated worktrees, with manually edited .git files a secondary concern. A file that deviates from the standard format is therefore treated as "\.git file broken", and trailing whitespace is interpreted as part of the path. Junio C Hamano took part in the thread, but his comments are not in the excerpts.