From e82f6da0a99444975cf15b8700853112b4e3c602 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Thu, 2 Jul 2026 00:40:31 +0200 Subject: [PATCH] fix(discover): use cbm_fopen for worktree gitlink + commondir reads Follow-up to #683 (@Naam). The worktree info/exclude fix read the `.git` gitlink file and its `commondir` with raw fopen(); on Windows raw fopen uses the ANSI code page and fails to open non-ASCII (e.g. CJK) repo paths, so a worktree indexed under such a path would silently not honor info/exclude / core.excludesFile. Switch both reads to cbm_fopen() (the UTF-8 -> _wfopen wrapper), matching the rest of discover.c (e.g. read_core_excludes_file at 248). No behavior change on POSIX (raw fopen already opens UTF-8 byte paths there); this is a Windows-only correctness/consistency fix, verified by the full test suite staying green and cross-platform CI. discover.c now has no raw fopen. Refs #682, #683 Signed-off-by: Martin Vogel --- src/discover/discover.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/discover/discover.c b/src/discover/discover.c index c3f36ace7..3fc31464e 100644 --- a/src/discover/discover.c +++ b/src/discover/discover.c @@ -778,8 +778,9 @@ static bool resolve_git_common_dir(const char *repo_path, char *common_dir, size return false; } - /* Linked worktree: parse "gitdir: " from the gitlink file. */ - FILE *f = fopen(dot_git, "r"); + /* Linked worktree: parse "gitdir: " from the gitlink file. + * cbm_fopen (not raw fopen) so non-ASCII repo paths open on Windows. */ + FILE *f = cbm_fopen(dot_git, "r"); if (!f) { return false; } @@ -811,7 +812,7 @@ static bool resolve_git_common_dir(const char *repo_path, char *common_dir, size * (typically a relative path like "../.."). Absent in single-worktree gitdirs. */ char commondir_path[CBM_SZ_4K]; path_join(commondir_path, sizeof(commondir_path), git_dir, "commondir"); - FILE *cf = fopen(commondir_path, "r"); + FILE *cf = cbm_fopen(commondir_path, "r"); if (cf) { char cbuf[CBM_SZ_4K]; bool resolved = false;