Skip to content

fix(ci): gate in a nested repo worktree checks devops-cli #7369

Done

Description

@dan-petty

Problem

devops ci in a worktree of another repository checks devops-cli and not that repository. The worktree is one of the clone repos/dan-petty/homelab, at .data/agent/worktrees/h-<issue> of the devops-cli checkout. The run prints Quality gate root: /workspaces/devops-cli and reads the workflow files of devops-cli. So devops ci --check --only actionlint,zizmor reports pass for a homelab branch whose workflow files it did not read. A pull request of that repository can then name a check result that is about a different tree.

Evidence

  • In the homelab worktree, on a branch that changes .github/workflows/k8s.yml and lint.yml: devops ci --check --only actionlint prints Quality gate root: /workspaces/devops-cli and pass [actionlint] (devops-cli main at 3e1bf8540). uv run --project /workspaces/devops-cli devops ci --check --only actionlint,zizmor gives the same root.
  • In the same folder, actionlint .github/workflows/*.yml and zizmor --offline .github/workflows/ read the homelab files.
  • Checkouts and Worktrees Below Another Repository Resolve to Their Own Repository #617 ("Checkouts and Worktrees Below Another Repository Resolve to Their Own Repository") is closed as completed.

Acceptance criteria

  • devops ci in a worktree of a clone below repos/ uses that worktree as the quality gate root, or it stops with a message that names the root it would check.
  • A test covers a worktree of a nested clone that is below the data directory of the outer checkout.

Alternatives check of 2026-11-27: in-use.
The repository already uses this tool.
Tool: git/git (https://github.com/git/git), NOASSERTION, last activity 2026-11-26, maintained.
Reason: Searches found no dedicated alternative: Git's rev-parse --show-toplevel, already wrapped as git_show_toplevel, resolves a linked worktree's own root, but it exits 128 on a stale worktree and leaves the gate cache keying and stop behaviour to project code.

Covers:

  • Resolves a linked worktree's own top level, not the outer checkout
  • Already wrapped as git_show_toplevel and used by devops review path
  • Runs from the current directory with no new dependency

Lacks:

  • Exits 128 when a linked worktree's git directory is gone
  • No gate cache or coverage-index keying by root
  • No stop message or gate orchestration; project code must change

Proposed design

Problem statement

devops ci in a linked worktree of a clone under repos/ announces the outer devops-cli checkout and reads its workflow files. A pull request of the nested repository can then cite a check result about a different tree. The fix makes the gate root the git worktree that holds the current directory. It stops outside a work tree and keys the cache and coverage index by the gate root.

Acceptance criteria

Requirement: Gate root from the git worktree

devops ci SHALL take its quality gate root from the git worktree that holds the current directory.

Scenario: Worktree of a clone below the data directory

  • WHEN A test builds an outer checkout with a clone at repos/<owner>/<name> and a linked worktree at .data/agent/worktrees/h-1. The test answers git rev-parse --show-toplevel with the worktree path. The test runs the gate there.
  • THEN The announced Quality gate root is the worktree path. Each process that the gate starts with a working directory runs in that worktree.

Requirement: Stale worktree still checked

When git rev-parse --show-toplevel fails for a stale linked worktree, the command MUST use the nearest ancestor with a .git entry and keep the stale-worktree warning.

Scenario: Stale linked worktree

  • WHEN A test removes the git directory of a linked worktree. The test answers git rev-parse --show-toplevel with exit 128. The test runs the gate from the worktree.
  • THEN The announced root is the worktree. The command prints the stale linked worktree warning.

Requirement: Stop outside a work tree

When the current directory is not in a git work tree, the command MUST stop with exit code 1 and name that directory.

Scenario: Directory that is not in a work tree

  • WHEN A test runs devops ci --check in a temporary directory with no .git entry in it or above it. The test answers git rev-parse --show-toplevel with exit 128.
  • THEN The command exits 1. It prints a message that names that directory. It starts no check.

Requirement: Cache and coverage index keyed by the gate root

The CI cache and coverage index of a gate run MUST be keyed by the quality gate root.

Scenario: Cache and coverage paths of the nested clone worktree

  • WHEN A test resolves the CI cache path and the coverage index path for the worktree .data/agent/worktrees/h-1 of a clone under repos/. The test resolves the same paths for the outer checkout.
  • THEN The cache path and the coverage index path of the worktree differ from those of the outer checkout. A passing gate run in the worktree writes the file named for the worktree.

Existing Tool Considered

The alternatives check in the issue body records git/git (https://github.com/git/git) with the verdict in-use. The block lists what Git covers and lacks. The proposal uses git_show_toplevel for the root. It adds a fallback to the nearest .git ancestor for a stale worktree. It adds a stop with the named directory outside a work tree. It keys the cache and coverage index by the gate root.

Key questions

  • Why does devops ci check the outer checkout in a worktree of a clone under repos/?: _get_project_root calls find_worktree_root. _checks_as_its_own_tree resolves a linked worktree whose owner is a clone under repos/ to the workspace. The clone is nested in the workspace by design. The gate then announces and checks the workspace. [sources: src/devops_cli/commands/ci.py:133, src/devops_cli/core/repo.py:241, src/devops_cli/core/repo.py:256, tests/commands/test_repos.py]
  • Which method gives the quality gate root of the worktree that holds the current directory?: Resolve it with git rev-parse --show-toplevel from the current directory through the existing git_show_toplevel. When Git cannot answer because the git directory of the worktree is gone, use the nearest ancestor that holds a .git entry. Stop when there is none. Keep find_worktree_root as it is, because every other command depends on its workspace resolution. (best practice) [sources: src/devops_cli/git/operations.py:664, src/devops_cli/commands/review.py:238, src/devops_cli/core/repo.py:55, tests/commands/test_ci.py, tests/commands/test_repos.py, src/devops_cli/commands/ci.py:133]
    • Chosen: git_show_toplevel, then the nearest .git entry for a stale worktree. Git answers with the worktree that holds the directory. The fallback keeps the stale-worktree warning.
    • Rejected: Keep find_worktree_root and fall back to it. It is the reported defect. For a worktree of a repos/ clone it names the outer checkout.
    • Rejected: Change find_worktree_root so a worktree of a repos/ clone checks itself. The repository records that such a worktree resolves to the workspace and asserts it. A change would move every command, not just the gate.
    • Rejected: Require a --root option on each call. The default stays wrong for the nested worktree. Each caller must remember the option.
  • Does a linked worktree below another checkout have its own git root?: Yes. A linked worktree has its own work tree. Its .git is a gitdir: file that names <common dir>/worktrees/<name>, and a commondir file names the shared git directory. git rev-parse --show-toplevel run there prints the worktree path. A worktree of a clone under repos/ is a work tree of its own too. find_worktree_root still resolves it to the workspace by design, which is the defect this issue fixes for the gate. [sources: src/devops_cli/core/repo.py:93, src/devops_cli/core/repo.py:100, src/devops_cli/git/operations.py:664, tests/commands/test_repos.py]
  • What does the command do when the current directory is not in a git work tree?: Stop with exit code 1 and a message that names the directory. Start no check. (best practice) [sources: src/devops_cli/commands/ci.py:133, src/devops_cli/core/repo.py:55, src/devops_cli/lang/en/messages.py:592, src/devops_cli/config/constants.py:2006]
    • Chosen: Stop and name the directory. Git gives no work tree there. A stop keeps the reported result tied to one tree and shows the premise that failed.
    • Rejected: Check the current directory. It reports a verdict for a tree that is not a work tree. The git-based checks of the gate fail there.
    • Rejected: Fall back to the devops-cli checkout. That fallback is the reported defect. The run checks a tree that the caller did not name.
    • Rejected: Use the nearest parent directory with a pyproject.toml. It can name another repository and hides the mistake.
  • By what key does a gate run name its cache and coverage-index files?: By the quality gate root itself (root.resolve()). A worktree of a clone under repos/ gets its own file and never writes to the file of the outer checkout. (best practice) [sources: src/devops_cli/ci/cache.py, tests/commands/test_ci.py, src/devops_cli/core/repo.py:241]
    • Chosen: The quality gate root. The gate root is the tree the verdict is about. Each worktree keeps its own file as the docstring promises.
    • Rejected: Keep find_worktree_root(root). It hashes every worktree of a clone as the workspace. Parallel worktrees overwrite each other and the file is named for a tree the run did not check.
    • Rejected: main_worktree_root(root). Every worktree would share one name, which loses the per-worktree separation.
  • Do the k8s and docs row failures belong to this issue?: No. They are separate defects in the gate rows. Defer them to new issues. The root fix stays in one pull request. (best practice) [sources: AGENTS.md]
    • Chosen: Defer them to separate issues. The root fix changes one resolution point. The row failures need their own causes and tests.
    • Rejected: Expand this issue to fix both rows. It mixes three defects in one pull request. It breaks the rule of one issue, one pull request.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Moved to new items

#7525, #7526

Activity

  1. added
    type/bug
    scope/ci
    source/agent
    status/new
    effort/medium
    on Nov 27, 2026
  2. dan-petty commented on Nov 27, 2026

    @dan-petty
    OwnerAuthor
    • Priority: The CI gate reports pass on the wrong files, which can let unverified changes merge.
  3. added
    value/high
    priority/p1-high
    on Nov 27, 2026
  4. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (6)

    Tools considered:

    Searches run:

    • git rev-parse --show-toplevel worktree root, results: 5
    • python library resolve git worktree root working tree directory, results: 5
    • GitPython working_tree_dir, results: 5
    • git rev-parse documentation show-toplevel, results: 5
    • git-scm.com docs git-rev-parse show-toplevel, results: 5
    • linked worktree .git file gitdir commondir show-toplevel, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 27, 2026
  7. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. dan-petty commented on Nov 28, 2026

    @dan-petty
    OwnerAuthor

    Two more failures of devops ci in a tree of dan-petty/homelab, seen on 2026-11-28 in a copy of homelab main (a review of the plan pull requests homelab#611, #617 and #632):

    • uv run devops ci --check --only k8s stops with ModuleNotFoundError: No module named 'tests'.
    • The docs row (devops docs check) exits 1 on homelab README.md lines 283 and 370: it reads <plan id> in a command example as an extra argument. It does not read k8s/README.md.

    So a verify of a homelab task that names either row fails on the base and after the change.

  9. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See Moved to new items in the section Proposed design of the body.

  10. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 28, 2026
  11. added
    status/in-review
    and removed
    status/in-progress
    on Nov 28, 2026
  12. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  13. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 14:05 UTC

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

    effort/mediumpriority/p1-highscope/cisource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions