Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Git dir followed unconditionally #12204

Closedscriptease(GitHub profile, opens in a new tab) opened this issue 3 comments

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/desktop

Steps to reproduce

  1. Create a folder in iCloud
  2. Use --git-dir to move the git metadata and files out outside the project
  3. Open the original folder in t3code as a project
  4. t3 opens the root project in the git folder instead and can't find anything like skills

Expected behavior

The follow to the git-dir and it's git-dir is fine, but if the back link is missing it should stay in the requested folder not a random git folder.

Actual behavior

Follows git-dir blindly and doesn't respect the folder the user requested.

Impact

Minor bug or occasional failure

Version or commit

Nightly latest

Environment

MacOS

Logs or stack traces

Screenshots, recordings, or supporting files

No response

Workaround

Fixed by setting the backlink:

git --git-dir=$HOME/.obsidian/git/v1 config core.worktree $HOME/obsidian/V1
  1. scriptease(GitHub profile, opens in a new tab) added labelsneeds-triage

  2. Triage

    Confirmed on current main (6d1d54944). This is a real server VCS / project-root bug, not a desktop-only picker glitch and not an iCloud-only filesystem quirk. Desktop is just the surface that opened the folder. Not already fixed. No later commit teaches T3 to keep the user-requested folder when git-dir has no core.worktree back-link. No duplicate found for separate-git-dir / core.worktree / iCloud+Obsidian layouts.

    What you reported. Vault (or other project) lives in iCloud. Git metadata was moved out with --git-dir (your paths: $HOME/.obsidian/git/v1 and $HOME/obsidian/V1). Opening the original folder in T3 relocates the “root project” into that git directory, so project-local things such as skills disappear. Setting the back-link fixes it:

    git --git-dir=$HOME/.obsidian/git/v1 config core.worktree $HOME/obsidian/V1

    That matches the code. T3 follows git-dir and then trusts Git’s idea of the main worktree. Without core.worktree, Git names the git directory itself as that worktree.

    What the code does

    1. Repo detection uses --show-toplevel and --git-common-dir, then treats the common dir as a cwd when it is not named .git.

    detectRepository records rootPath from --show-toplevel and metadataPath from --git-common-dir:

    https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/vcs/GitVcsDriver.ts#L535-L558

    resolveRepositoryPaths does the same split (worktreeRoot vs gitCommonDir):

    https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/vcs/GitVcsDriverCore.ts#L1099-L1178

    For fetches, default-branch lookups, remotes, and worktree list, cwd is:

    path.basename(gitCommonDir) === ".git" ? path.dirname(gitCommonDir) : gitCommonDir

    https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/vcs/GitVcsDriverCore.ts#L1082-L1087

    A normal repo (…/project/.git) stays in the project. A separate git-dir named v1 is used as cwd. That is the unconditional follow.

    2. git worktree list reports the git-dir as the main worktree for this layout.

    listRefs maps each local branch to a path from git --git-dir <common> worktree list --porcelain. Git does not reconstruct the real checkout from a gitdir: pointer. For --git-dir=$HOME/.obsidian/git/v1 it prints:

    worktree /Users/…/.obsidian/git/v1

    even when you ran the command from $HOME/obsidian/V1. T3 then keeps that path if stat succeeds (the git dir exists):

    https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/vcs/GitVcsDriverCore.ts#L271-L299 https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/vcs/GitVcsDriverCore.ts#L2736-L2781

    3. That fake worktree is eligible for reuse.

    preparePullRequestThread reuses a branch worktree whenever its listed path is not the project cwd. Vault cwd ≠ git-dir, so it will treat $HOME/.obsidian/git/v1 as an existing worktree and hand the thread that path:

    https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/git/GitManager.ts#L2322-L2507

    Same class of mistake anywhere else we prefer ref.worktreePath over the folder the user opened.

    4. Skills are scanned from cwd, not from the git-dir.

    Cursor (and the other drivers) look under <cwd>/.agents/skills, <cwd>/.cursor/skills, <cwd>/.claude/skills, etc.:

    https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/provider/Drivers/CursorSkills.ts#L218-L230

    A git directory is objects/, refs/, HEAD. There are no skills there. That is the “can’t find anything like skills” report.

    5. core.worktree is the missing back-link, and T3 never reads it.

    git rev-parse --show-toplevel from the vault is often already the vault when a .git file (gitdir: …) is present. --show-toplevel / --is-inside-work-tree from the git-dir fail unless core.worktree is set. T3 never consults core.worktree. There is no test for --separate-git-dir / a gitdir: pointer that does not point at …/worktrees/….

    AgentSessionScanner.readGitIdentity follows gitdir: only to classify worktrees vs main repos. A pointer at ~/.obsidian/git/v1 is treated as a normal repository, not as “stay in the folder that had the pointer”:

    https://github.com/pingdotgg/t3code/blob/6d1d549441be84f19696ab59ed7e2fbf305280d4/apps/server/src/project/AgentSessionScanner.ts#L688-L728

    Why the workaround works

    core.worktree is Git’s back-pointer from the external git-dir to the checkout you opened. After it is set, --show-toplevel and work-tree operations resolve to $HOME/obsidian/V1 even when T3 runs git with --git-dir. T3 should do the equivalent itself: if that back-link is missing, keep the requested folder. Following git-dir for metadata is fine. Relocating the project/thread cwd to the git-dir is not.

    Fix direction

    • Resolve the working tree with git -C <user-opened-path> rev-parse --show-toplevel. If that fails or returns the git-dir / --git-common-dir, keep the opened path.
    • Do not use basename(gitCommonDir) === ".git" ? dirname : gitCommonDir as a project or thread cwd. That is only valid as a process cwd for --git-dir metadata commands.
    • Ignore git worktree list entries that are the git-dir, fail --is-inside-work-tree, or are not the user-opened folder / a real linked worktree under …/worktrees/….
    • Do not reuse those paths in preparePullRequestThread (or any “branch already has a worktree” path).
    • Optional: read core.worktree and use it when present; never invent a root from the git-dir when it is absent.
    • Cover this with a fixture: vault + echo gitdir: $GITDIR > .git + unset core.worktree. Opening the vault must keep that cwd for listing, skills, and worktree reuse.

    Reporter workaround stands. Safe to keep using until this ships.

  3. juliusmarminge added labelsaccepted

  4. juliusmarminge removed labelsneeds-triage

  5. juliusmarminge added labelsvia-triage

  6. Update

    The workaround only works for the T3 Code react app, but it doesn't work for the T3 Code swift code app.

    But if you create a thread in the T3 Code react app or desktop app and then open it in the T3 Code swift app then it works.

    Very weird.

  7. Verified on current main b5a226e49c with the real web dev server on Linux: created a checkout using git init --separate-git-dir=/tmp/triage-12204/metadata/project.git /tmp/triage-12204/icloud/Project, left core.worktree unset, added the original checkout through Add project → Local folder, then selected master.

    The project stayed at /tmp/triage-12204/icloud/Project; its checkout-local .agents/skills/repro/SKILL.md appeared in the composer both before and after branch selection. Git itself still reports the metadata directory in git worktree list, so the fixture exercises the missing-backlink case. The existing regression test does not report a separate git dir as the worktree of its branch passes (1 passed).

    Already fixed by #14157, merged as 462810f0b8. Closing as fixed. macOS iCloud and the Electron shell were not verified here.

    Capture: real web client, 1280 × 800, light theme, showing checkout-local skill discovery after branch selection.

    Checkout-local skill found with external Git metadata and no backlink

  8. juliusmarminge closed this

Sign in to join this conversation.