Skip to content

Checkouts and Worktrees Below Another Repository Resolve to Their Own Repository #617

Closed

Description

@dan-petty

Problem

Worktree and data-directory resolution (#582, #612, #553) starts from the top-most parent directory holding .git or pyproject.toml. That rule dates from v0.1.8, so that commands run inside a repository cloned under repos/ resolve to the devops-cli workspace. It also means that a checkout, or a linked worktree, placed below another directory holding .git or pyproject.toml resolves to that outer directory:

  • a project inside a home directory kept in git, such as a dotfiles repository;
  • a linked worktree placed inside a different repository or workspace.

In that case shared data goes to the outer directory's .data, and a checkout below it gates like a repos/ clone. This is not a regression: it has been the behaviour since before #585. #614 and the #553 follow-up record it with strict xfail tests. devops workspace clean refuses the outer workspace's data directory where it can recognise it.

Expected

A repository's own checkout, and its worktrees, resolve to that repository's main worktree however deeply they are nested. Clones under the workspace's repos/ still resolve to the workspace. The rule has to tell "a repository nested in a workspace by design" apart from "a checkout that happens to sit below an unrelated repository", and that distinction is not yet specified.

Proposed design

Problem statement

When a repository checkout or worktree is placed below another directory containing .git or pyproject.toml, the system incorrectly resolves to the outer directory's workspace instead of the checkout's own repository. This causes shared data to go to the wrong location and affects how checkouts are treated in commands like devops workspace clean.

Acceptance criteria

  • Criterion 1: A checkout or worktree nested within another repository resolves to its own repository's main worktree, regardless of nesting depth.
    Verification: Run a command inside a nested checkout/worktree and verify that it uses the data directory from the nested repository instead of an outer one.
  • Criterion 2: Clones under the workspace's repos/ still resolve to the workspace as before.
    Verification: Verify that a clone placed directly in the workspace's repos/ directory resolves correctly to the workspace's data directory.
  • Criterion 3: The system distinguishes between repositories nested in a workspace by design and those that happen to sit below unrelated repositories.
    Verification: Test both scenarios: one where a checkout is intentionally placed inside a workspace, and another where it accidentally sits under an unrelated repository; verify correct resolution in each case.

Key questions

  • Should the resolution rule be changed to differentiate between intentional nesting and accidental nesting?: Yes, the rule must distinguish 'a repository nested in a workspace by design' from 'a checkout that happens to sit below an unrelated repository'. (proposed)

Open questions

  • What is the current behavior when a checkout or worktree is nested below another repository? (missing verified source)
  • How does the system currently determine which repository a checkout belongs to? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added this to the v0.2.25 milestone on Sep 25, 2026
  2. added
    type/bug
    scope/cli
    priority/p2-medium
    on Sep 25, 2026
  3. removed this from the v0.2.25 milestone on Sep 30, 2026
  4. dan-petty commented on Sep 30, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to the backlog. v0.2.25 is capped at 12 items (#740), and only the next two planned releases keep a milestone (#739), so P2 items wait in the backlog until reprioritization pulls them in.

  5. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #700, whose worktree inventory leaves root resolution to this item (core/repo.py:65-67, :156-175). Found by the 2026-10-08 backlog review.

  6. added this to the v0.2.39 milestone on Oct 17, 2026
  7. dan-petty commented on Oct 21, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1806, merged into release/v0.2.39 as bca9455.

    Summary

    Differentiate repositories nested by design from accidental nesting under an unrelated repository.
    A checkout or worktree sitting below another directory holding .git or pyproject.toml resolves to its own repository's main worktree, while submodules, repos/ clones, and workspace worktrees continue to resolve to the enclosing workspace.

    6 file(s) changed.

    How it was verified

    Check runs at 985ddec:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • zizmor: pass
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • DevContainer Image: skipping
    • Fail-to-Pass Check: pass
    • Fail-to-Pass Self-Check: pass
    • Changed-Test Independence: pass
    • Rule Pack Tests: pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Analyze (actions): pass
    • Static Analysis: pass
    • Service Image: skipping
    • Dependency Freshness: skipping

    Acceptance Criteria of docs/agent/tasks/task-617-checkouts-and-worktrees-below-another-repository-resolve-to-their-own-repository.md:

    • Criterion 1: A checkout or worktree nested within another repository resolves to its own repository's main worktree, regardless of nesting depth.
    • Criterion 2: Clones under a workspace's repos/ (and git submodules) still resolve to the enclosing workspace.
    • Criterion 3: The system differentiates repositories nested by design (repos/ clones, submodules, worktrees of the workspace) from accidental nesting under an unrelated repository.
    • Criterion 4: cleanup_data_directory safely cleans its own data without affecting host data, and refuses to prune outer workspace data when explicitly configured.
    • Removed _OUTER_DIRECTORY_LIMIT xfail marks in tests/test_data_dir_worktrees.py; tests now pass strictly.
    • test_a_worktree_of_a_checkout_inside_another_repository_checks_itself in tests/test_repos.py passes without xfail.
    • Added test_deeply_nested_unrelated_checkouts_and_worktrees_resolve_to_own_repositories testing multi-level nesting.
    • changelog.d/617.md records the fix under ### Fixed.
  8. added a commit that references this issue on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/clitype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions