git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 5/5] worktree repair: avoid breaking unrelated .git file and gitdir

From
Yoichi NAKAYAMA <yoichi.nakayama@gmail.com>
Date
Oct 17, 2026, 02:40 UTC
Message-ID
<CAF5D8-tTmruFLpCY4WpCkMU+3ng9pHp22MrTcUrKbXfWmhzoow@mail.gmail.com>
In-Reply-To
<xmqq8q3yon7p.fsf@gitster.g>
On Fri, Oct 16, 2026 at 3:03 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 43 quoted lines
>
> "Yoichi NAKAYAMA via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > diff --git a/worktree.c b/worktree.c
> > index 879941a977..86094307b1 100644
> > --- a/worktree.c
> > +++ b/worktree.c
> > @@ -640,7 +640,11 @@ int other_head_refs(struct repository *repo,
> >  static const char *get_worktree_id(const char *dotgit_contents)
> >  {
> >       const char *slash = find_last_dir_sep(dotgit_contents);
> > -     if (!slash)
> > +     const char *prefix = "/worktrees";
> > +     int prefixlen = strlen(prefix);
> > +     if (!slash ||
> > +         slash - dotgit_contents < prefixlen ||
> > +         strncmp(slash - prefixlen, prefix, prefixlen))
> >               return "";
> >       return slash + 1;
>
> Just being curious, but slash is found by scanning dotgit_contents
> for either '/' or '\'.  We make sure what comes before the slash
> is "/worktree".
>
> Could there be situations where this code needs to accept
>
>         "...\worktrees\my-worktree"
>
> where slash points at the backslash before "my-worktree"?  Because
> somebody wrote the pathname with backslash before the worktree name,
> it would be natural to expect another backslash before the "worktrees"
> constant, no?  For that matter, would this code need to also accept
>
>         ".../worktrees//my-worktree"
>
> where three are extra/duplicated slashes (or backslashes)?  The
> normal code paths to create these directories and records the path
> to these directories should hopefully be using the canonical '/'
> without unnecessary duplicate slashes, but (1) existing use of
> find_last_dir_sep() might be a sign that we may have to deal with
> backslashes, and (2) since this is about reparing a broken set-up,
> it does not seem too far-fetched to attempt dealing with the above
> two sample input, hence this question.

While Git doesn't create a .git file with backslash separators, it can find the repository from such .git file on Windows. So I think 'worktree repair' should handle it.

I will also add handling for duplicated separators.
Thanks,
-- 
Yoichi NAKAYAMA
Previous: Junio C HamanoNext: Junio C Hamano
Message 15 of 23 in “worktree repair: avoid breaking unrelated .git file and gitdir”
  1. 0/2 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Sep 13, 2026
  2. 1/2 worktree repair: refactor and reduce .git file readsYoichi NAKAYAMA via GitGitGadget, Sep 13, 2026
  3. Junio C HamanoOct 8, 2026
  4. Yoichi NAKAYAMAOct 11, 2026
  5. Yoichi NAKAYAMAOct 12, 2026
  6. 2/2 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Sep 13, 2026
  7. Yoichi NAKAYAMAOct 8, 2026
  8. 0/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  9. 1/5 worktree repair: align .git file handling with repair_gitfile()Yoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  10. 2/5 worktree repair: centralize inferred backlink selectionYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  11. 3/5 worktree repair: use read_gitfile_raw() in infer_backlink()Yoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  12. 4/5 worktree repair: reduce .git file readsYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  13. 5/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 14, 2026
  14. Junio C HamanoOct 15, 2026
  15. Yoichi NAKAYAMAOct 17, 2026
  16. Junio C HamanoOct 14, 2026
  17. Yoichi NAKAYAMAOct 15, 2026
  18. 0/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  19. 1/5 worktree repair: align .git file handling with repair_gitfile()Yoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  20. 2/5 worktree repair: centralize inferred backlink selectionYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  21. 3/5 worktree repair: use read_gitfile_raw() in infer_backlink()Yoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  22. 4/5 worktree repair: reduce .git file readsYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026
  23. 5/5 worktree repair: avoid breaking unrelated .git file and gitdirYoichi NAKAYAMA via GitGitGadget, Oct 17, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.