Skip to content

fix(repos): worktrees prune counts a nested .venv as data #6636

Description

@dan-petty

Problem

Checked at main (0fb04e1).

  • CONST_WORKTREE_REGENERABLE_PATHSPECS (src/devops_cli/config/constants.py:796-816) excludes .venv, dist, build and htmlcov only at the root of a worktree (:(exclude).venv). The cache directories __pycache__, .pytest_cache, .ruff_cache, .mypy_cache, .hypothesis and node_modules use :(exclude,glob)**/<name>/**, so they match at any depth.
  • A service repository can keep its uv project in a subdirectory, for example services/<name>/pyproject.toml. Then uv run --directory services/<name> makes services/<name>/.venv. count_ignored_data_files (src/devops_cli/git/worktree_inventory.py:243) counts each file of that .venv as data.
  • Result, 2026-11-21: in a service repository with such a project, devops repos worktrees prune --repo-dir <clone> refused all 9 worktrees of merged pull requests with "holds 1358 ignored data files". git ls-files --others --ignored --exclude-standard in one of them listed only services/<name>/.venv, __pycache__, .pytest_cache and .ruff_cache. The prune removed nothing, and worktrees add --reclaim keeps the same worktrees.

Proposed remedy

  • Change the .venv pathspec to :(exclude,glob)**/.venv/**, so that a virtual environment at any depth is a cache, as __pycache__ already is.
  • Keep dist, build and htmlcov at the root only, unless a test shows the same need: a nested build directory can hold files that are not a cache.

Acceptance criteria

  • A test makes a worktree whose only ignored files are in sub/project/.venv, and count_ignored_data_files returns 0.
  • A test makes a worktree with an ignored file in .data/agent/ and one in sub/project/.venv, and the count is 1.
  • devops repos worktrees prune previews a merged worktree that holds only a nested .venv as removable.

Alternatives check of 2026-11-21: none.
Tool: none found.
Reason: Searches returned only unrelated MDN pages; no maintained tool counts non-regenerable ignored files in a git worktree. The remedy is a one-line change to the project's own pathspec constant, which git already supports.

Proposed design

Problem statement

devops repos worktrees prune counts each file of a nested virtual environment as ignored data. A service repository that keeps its uv project in services/<name> gets services/<name>/.venv. Prune then refuses each such worktree with a high count, and the reclaim of worktrees add keeps the same worktrees. The fix excludes a .venv directory at any depth, as the cache directories already are.

Acceptance criteria

Requirement: Nested virtual environment is a cache

The count of ignored data files SHALL exclude the contents of a .venv directory at any depth of a worktree.

Scenario: A worktree holds only a nested virtual environment

  • WHEN A test makes a worktree whose ignored files are only under sub/project/.venv and calls count_ignored_data_files.
  • THEN The call returns 0.

Requirement: Data file beside a nested virtual environment

The count of ignored data files SHALL include each ignored file that is not under a regenerable path.

Scenario: A data file beside a nested virtual environment

  • WHEN A test makes a worktree with an ignored file in .data/agent/ and an ignored file in sub/project/.venv and calls count_ignored_data_files.
  • THEN The call returns 1.

Requirement: Nested build directory is data

The count of ignored data files MUST include the contents of a build directory below the root of a worktree.

Scenario: A nested build directory

  • WHEN A test makes a worktree with an ignored file in sub/project/build/ and calls count_ignored_data_files.
  • THEN The call returns 1.

Requirement: Prune preview of a nested virtual environment

devops repos worktrees prune SHALL mark a merged worktree whose only ignored files are under a nested .venv as removable.

Scenario: Prune previews a worktree with a nested virtual environment

  • WHEN A test runs devops repos worktrees prune --repo-dir <clone> with no --confirm against a clone whose merged worktree holds ignored files only under sub/project/.venv.
  • THEN The preview lists that worktree as removable and the command removes no worktree.

Existing Tool Considered

No open, maintained tool covers the need. The block Alternatives check of 2026-11-21: none in the issue body records the verdict none and no tool. The change uses the pathspec magic of git, which the project already uses at src/devops_cli/config/constants.py:797. Written cost of the own code: about 2,000 tokens to write the pathspec entry and four tests, about 5,000 tokens to keep and fix them for one year, and less than one hour of elapsed time.

Key questions

  • Which code counts the ignored data files of a worktree, and which pathspecs does it use?: count_ignored_data_files at src/devops_cli/git/worktree_inventory.py:243 runs git ls-files --others --ignored --exclude-standard with CONST_WORKTREE_REGENERABLE_PATHSPECS at line 271. The constant is at src/devops_cli/config/constants.py:797. [sources: src/devops_cli/git/worktree_inventory.py:243, src/devops_cli/git/worktree_inventory.py:271, src/devops_cli/config/constants.py:797]
  • Which form excludes a virtual environment at any depth?: Add :(exclude,glob)**/.venv/** to CONST_WORKTREE_REGENERABLE_PATHSPECS and keep :(exclude).venv for the root. This is the form that the cache entries already use. (best practice) [sources: src/devops_cli/config/constants.py:797, src/devops_cli/git/worktree_inventory.py:271]
    • Chosen: Add a glob entry at any depth and keep the root entry. The root entry keeps the current behavior at the root. The glob entry adds each deeper path, as the cache entries already do.
    • Rejected: Replace the root entry with the glob entry. The spec lists .venv at the root, and no test proves the glob form of the root case.
    • Rejected: Filter the paths in Python after git ls-files. It adds code that the pathspec of git gives, and it splits the rule across two places.
  • Which paths stay at the root only?: Keep dist, build and htmlcov at the root only. The change adds no glob entry for them. (best practice) [sources: src/devops_cli/config/constants.py:797, openspec/specs/repos-worktrees-prune/spec.md:134]
    • Chosen: Keep dist, build and htmlcov at the root only. A nested build directory can hold files that are not a cache. A test must show the need before a wider exclude.
    • Rejected: Exclude dist, build and htmlcov at any depth. No test shows the need, and a wider exclude hides data files.
  • Which documents and tests state the regenerable path list?: openspec/specs/repos-worktrees-prune/spec.md:134 states the list, and its scenario at :111 uses a root .venv. The scenario at openspec/specs/repos-worktrees-add/spec.md:173 uses caches at any depth. CONTRIBUTING.md:225 names the list in prose. tests/git/test_repos_worktrees_reclaim_scope.py holds the tests of the paths. The change updates the two spec files. [sources: openspec/specs/repos-worktrees-prune/spec.md:134, openspec/specs/repos-worktrees-prune/spec.md:111, openspec/specs/repos-worktrees-add/spec.md:173, CONTRIBUTING.md:225, tests/git/test_repos_worktrees_reclaim_scope.py]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. dan-petty commented on Nov 21, 2026

    @dan-petty
    OwnerAuthor
  2. added
    type/bug
    source/agent
    status/new
    value/medium
    effort/low
    scope/repos
    priority/p2-medium
    on Nov 21, 2026
  3. devops-cli-service commented on Nov 21, 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 (7)

    Searches run:

    • git pathspec exclude .venv at any depth glob magic, results: 5
    • tool to list git ignored files excluding cache directories worktree prune, results: 5
    • git ls-files --others --ignored --exclude-standard nested .venv pathspec exclude, results: 5
    • prune stale git worktrees merged branches tool open source, results: 5
    • pathspec python library git pathspec exclude magic support, results: 5
    • "git worktree" cleanup tool removes merged worktrees ignores untracked files venv, results: 5
    • gitglossary pathspec exclude glob magic git-scm documentation, results: 5

    Sources:

  4. added
    status/ready
    and removed
    status/new
    on Nov 22, 2026
  5. devops-cli-service commented on Nov 22, 2026

    @devops-cli-service
    Contributor

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

  6. added
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  7. removed
    status/in-review
    on Nov 25, 2026
  8. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-25 08:43 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/lowpriority/p2-mediumscope/repossource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions