From aaa4299a2839b95aa01be18c133470c4500411e0 Mon Sep 17 00:00:00 2001 From: bb Date: Fri, 7 Aug 2026 12:46:35 -0500 Subject: [PATCH] fix(gateway): normalize common repo root separators in the git probe `common_repo_root` derives its answer via `os.path.realpath` + `os.path.dirname`, which rewrite separators to the platform-native `\` on Windows, while `repo_root` returns raw `--show-toplevel` output (always forward slashes). The same directory therefore came back spelled two ways from a single `resolve()` call, so callers comparing the two roots for identity could not see that a repo's own checkout IS its common root. Normalize the derived path back to git's forward-slash spelling so both probes agree byte-for-byte. --- tui_gateway/git_probe.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tui_gateway/git_probe.py b/tui_gateway/git_probe.py index 693ac417032cf..96053d85cdb90 100644 --- a/tui_gateway/git_probe.py +++ b/tui_gateway/git_probe.py @@ -141,6 +141,14 @@ def common_repo_root(cwd: str) -> str: splits every worktree into a separate "repo". The common ``.git`` dir (``--git-common-dir``) is shared by a repo and all its worktrees, so its parent is the one true repo root; fall back to the toplevel root otherwise. + + The returned path is normalized to git's forward-slash spelling so it can be + compared against :func:`repo_root` (which returns raw ``--show-toplevel`` + output). ``os.path.realpath`` rewrites separators to the platform's native + ``\\`` on Windows, so without this the SAME directory came back spelled two + ways and the repo's own checkout compared unequal to its common root — the + main checkout was then misread as a linked worktree and the desktop sidebar + rendered it twice (a dir-labeled lane plus a branch-labeled ``main`` lane). """ if not cwd: return "" @@ -150,7 +158,7 @@ def common_repo_root(cwd: str) -> str: if gitdir: gitdir = os.path.realpath(gitdir) if os.path.basename(gitdir) == ".git": - return os.path.dirname(gitdir) + return os.path.dirname(gitdir).replace(os.sep, "/") return repo_root(cwd) return _cache.resolve(f"common:{cwd}", _probe)