Skip to content

_git_toplevel misses a home-rooted repo when workspace/ is a separate mount (no GIT_DISCOVERY_ACROSS_FILESYSTEM) #2245

Closed

Description

@trinity-ability

Problem

_git_toplevel (shipped in #2077 for #2075) asks git for the agent's repo root:

"git -c safe.directory='*' -C \"$start\" rev-parse --show-toplevel 2>/dev/null"

$start is /home/developer/workspace when that directory exists, /home/developer otherwise.

Git stops repository discovery at a filesystem boundary by default. If an agent has /home/developer/workspace as a separate mount — a bind mount, a distinct volume, an overlay — then rev-parse --show-toplevel started inside it will not walk up into /home/developer, even when the repository is genuinely rooted there.

_git_toplevel then returns None, and _detect_git_dir falls through to _detect_git_dir_fallback — the pre-#2075 content heuristic. On that topology, a populated workspace/ answers /home/developer/workspace, which is exactly the misclassification #2075 exists to eliminate. Every path-based consumer (the compatibility collector, the .gitignore migration and its .git guard, the compatibility fix endpoint) then reads and writes a subdirectory's files as if they were the repo root's.

The fallback is correct as a no-repository path. The defect is that a boundary makes a repository that does exist look like it does not.

Fix

Set GIT_DISCOVERY_ACROSS_FILESYSTEM=1 for this probe:

GIT_DISCOVERY_ACROSS_FILESYSTEM=1 git -c safe.directory='*' -C "$start" rev-parse --show-toplevel

Safe here specifically because _git_toplevel already refuses any answer outside /home/developer — discovery may cross the boundary, but the result is still confined before it is trusted.

Provenance

Spotted in #2076, a competing implementation of the #2075 fix that carried this flag and was closed as superseded by #2077. #2077 is the better change overall (docs + a 251-line test file); this one flag is the single thing it does not have. Recorded so the idea is not lost with the closed PR.

Acceptance criteria

  • _git_toplevel sets GIT_DISCOVERY_ACROSS_FILESYSTEM=1
  • A regression test in tests/unit/test_2075_detect_git_dir.py covers the boundary case: git answers empty/non-zero from inside workspace/ while a home-rooted repo exists, and the result is /home/developer rather than the fallback's workspace/
  • The containment check (answer must be /home/developer or beneath) is unchanged and still pinned by a test

Activity

  1. added
    status-in-progress
    on Aug 17, 2026
  2. self-assigned this
    on Aug 17, 2026
  3. added
    status-in-dev
    and removed
    status-in-progress
    on Aug 17, 2026
  4. removed
    status-in-dev
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority-p2theme-reliabilitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions