Skip to content

fix(repos): the template row removes a file of an old baseline #7310

Done

Description

@dan-petty

Problem or Motivation

Row 9 of devops repos onboard (Template pull request) cannot correct a template pull request that an earlier run opened with a wrong answer.

Read on 2026-11-26 on #7307, which a run with the default release_type: simple opened with version.txt:

  • A second run with --release-type python plans only add .copier-answers.yml. template_row of src/devops_cli/github/onboard/template_pr.py pushes the files that are absent or differ; it removes no file that the new baseline does not hold. So version.txt stays on the branch.
  • The branch is ci/repository-template (src/devops_cli/github/onboard/routes.py:27). The commit hook of the repository refuses a commit on it: branch name is <type>/<issue>-<slug> or copilot/<slug> (CONTRIBUTING.md, Naming). The command writes its commit through the API, so no person or agent can correct the branch with git.

The only way out is to close the pull request, delete the branch and run the command again.

Proposed Solution

Disposition: change the code.

  • When a template pull request is open, the run makes the tree of its branch equal to the baseline for the template files: it adds, replaces and removes. A file that only an earlier baseline held, such as version.txt, goes. The plan prints remove <path> for it.
  • The branch name follows the naming rule of the repositories, or the hook accepts the template branch by name. Name the choice in the plan of this item.

Proof: a test over the fake GitHub API with an open template pull request that holds version.txt, and a baseline with no such file, gives a tree with no version.txt and the change line remove version.txt.

Existing Tool Considered

The git data API of GitHub (trees and commits), which the row already uses. A tree entry with sha: null removes a path.

Alternatives check of 2026-11-26: in-use.
The repository already uses this tool.
Tool: copier-org/copier (https://github.com/copier-org/copier), MIT, last activity 2026-11-26, maintained.
Reason: Searches found Copier, the template engine behind the baseline's .copier-answers.yml. It re-renders a project and applies the template diff with deletions, but it cannot drive the open branch through the API, so the row still needs code.

Covers:

  • Re-renders the project from the new baseline with the new answers
  • Applies the template diff, including deletions of dropped files
  • Keeps answers in .copier-answers.yml for a repeatable render

Lacks:

  • No tree push to an open pull request branch over the API
  • No plan lines such as remove <path>
  • No branch-name rule for the commit hook
  • Needs a local clone and git, not a fake GitHub API

Proposed design

Problem statement

Row 9 of devops repos onboard cannot correct an open template pull request that an earlier baseline filled with a file the new baseline lacks: the branch keeps the stale file, so the only way out is to close the pull request, delete the branch and run the command again. The branch ci/repository-template is also outside the branch-name rule, so a person cannot commit a correction on it. The change makes row 9 build the branch's tree from the default branch and the new baseline, so a file of an old baseline goes and the plan says remove <path>, and it lets the hook accept the template branch by name.

Acceptance criteria

Requirement: Remove a file of an old baseline

Row 9 SHALL remove from the template branch each file that an earlier run of the row wrote and the new baseline does not hold.

Scenario: Open template pull request with a dropped file

  • WHEN The open template pull request branch holds version.txt, the default branch holds each file of the new baseline, and the new baseline holds no version.txt.
  • THEN tests/github/onboard/test_onboard_rows.py::test_template_row_removes_dropped_baseline_file passes: the branch tree of the fake GitHub API holds no version.txt, and the row changes hold remove version.txt.

Requirement: Plan the removal without a write

Row 9 SHALL show each removed path as remove <path> in a plan and SHALL send no tree write in a plan.

Scenario: Plan of a dropped file

  • WHEN The open template pull request branch holds version.txt, the new baseline holds no version.txt, and writer.confirm is false.
  • THEN tests/github/onboard/test_onboard_rows.py::test_template_row_plans_removal_without_write passes: the row changes hold remove version.txt, and the fake API records no template-tree request.

Requirement: Keep a file of the default branch

Row 9 SHALL keep a path that the default branch holds and the new baseline does not hold.

Scenario: Default branch file outside the baseline

  • WHEN The default branch and the template branch hold README.md, and the new baseline holds no README.md.
  • THEN tests/github/onboard/test_onboard_rows.py::test_template_row_keeps_default_branch_file passes: the branch tree still holds README.md, and the row changes hold no remove README.md.

Requirement: Match the default branch outside the template files

Row 9 SHALL give each path that the new baseline does not hold the text of the default branch.

Scenario: Branch copy of a default branch file differs

  • WHEN The template branch holds README.md with text other than the default branch's README.md, and the new baseline holds no README.md.
  • THEN tests/github/onboard/test_onboard_rows.py::test_template_row_restores_default_branch_text passes: the branch tree holds the default branch's text of README.md.

Requirement: Accept the template branch in the hook

The branch-name pre-commit hook MUST accept ci/repository-template as an exact branch name beside the two branch forms.

Scenario: Template branch passes the hook

  • WHEN The checkout is on the branch ci/repository-template, and uv run pre-commit run branch-name --all-files runs.
  • THEN The command reports Passed; on a checkout of a branch named ci/other the same command reports Failed.

Existing Tool Considered

Copier (copier-org/copier), the tool that the alternatives block of the issue body names with the verdict in-use and that the baseline already uses. Its block lists what the tool lacks for row 9, so the row keeps its thin adapter over the GitHub Git data API that it already uses (src/devops_cli/github/onboard/template_pr.py:148), about 60 lines, at a written cost of about 25,000 tokens and 3 hours to build, keep and fix.

Key questions

  • How does row 9 make the tree of the open template branch lose a path that the new baseline does not hold?: This run found no verified source for a tree entry whose sha is null, so row 9 does not use it. It sends the tree of the default branch's head commit as base_tree and adds the baseline files that the default branch lacks, so a path of an old baseline is in neither the default branch's tree nor the entries and goes. A plan reads the tree of the template branch head and the tree of the default branch head with recursive=1 and names each path that is on the branch, absent from the default branch and absent from the baseline as remove <path>; the confirmed run sends the same one tree request, which the row already sends (src/devops_cli/github/onboard/template_pr.py:161). (best practice) [sources: src/devops_cli/github/onboard/template_pr.py:161, src/devops_cli/github/onboard/template_pr.py:165, tests/support/github_repository.py:750, src/devops_cli/github/onboard/routes.py:368]
    • Rejected: Send a tree entry with sha: null for each removed path. No source of this run states that behavior, and the fake GitHub API of the tests merges only entries that hold content (tests/support/github_repository.py:750-754).
    • Chosen: Build the tree from the default branch's tree and the baseline files it lacks. It uses the base_tree request that the row already sends (src/devops_cli/github/onboard/template_pr.py:161-171), so the branch holds exactly the default branch's tree plus the template files the repository lacks.
    • Rejected: Report the removals from the file list of the pull request. The list names changes, not the tree, and GitHub caps it, so it cannot show that the default branch lacks a path.
  • Which branch-name rule applies to ci/repository-template?: Keep ci/repository-template and add it as an exact third alternative of the branch-name hook's --pattern, with the hook's name and comment stating it. Do not weaken the general rule. The name is outside <type>/<issue>-<slug> because the form needs an issue number and the target repository has no issue for the template, and a rename would orphan each open template pull request. (best practice) [sources: CONTRIBUTING.md:206, src/devops_cli/github/onboard/routes.py:28, .pre-commit-config.yaml:20, openspec/specs/branch-name-hook/spec.md:8]
    • Rejected: Rename the branch to a <type>/<issue>-<slug> name. The target repository has no issue for the template, the issue number would name another repository's issue, and a rename orphans each open template pull request.
    • Chosen: Add ci/repository-template to the exact accepted names. It keeps the machine branch and the open pull request, and it leaves the general rule intact.
    • Rejected: Accept every branch under ci/. It weakens the hook for each branch and hides a wrong name.
  • How does row 9 select the paths to remove from an open template branch?: Read the tree of the head of TEMPLATE_BRANCH and the tree of the default branch head, and remove a path only when it is on the template branch, absent from the default branch and absent from the new baseline. (best practice) [sources: src/devops_cli/github/onboard/template_pr.py:245, src/devops_cli/github/onboard/routes.py:368]
    • Rejected: Remove every path of the branch that the new baseline lacks. It removes files that the default branch owns.
    • Chosen: Compare the branch tree with the default branch tree and the new baseline. It removes only paths that the template pull request added and the new baseline dropped.
    • Rejected: Use the files list of the open pull request. The list shows changes, not the full tree. It cannot prove that a path is absent from the default branch.
  • Does row 9 reconcile an open template branch when the default branch holds every baseline file?: Yes. The open branch can hold a file of an old baseline while the default branch holds every file of the new baseline, so row 9 reconciles the open branch before it returns PRESENT; it returns PRESENT only when the branch tree already equals the default branch's tree plus the baseline files that the default branch lacks. (best practice) [sources: src/devops_cli/github/onboard/template_pr.py:247, src/devops_cli/github/onboard/template_pr.py:252]
    • Rejected: Return PRESENT when the default branch holds every baseline file. It leaves the stale file on the open template branch.
    • Chosen: Reconcile the open template branch before the PRESENT result. It removes the stale file and keeps the open pull request usable.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    source/agent
    status/new
    value/medium
    on Nov 26, 2026
  2. dan-petty commented on Nov 26, 2026

    @dan-petty
    OwnerAuthor
  3. added
    effort/medium
    scope/repos
    priority/p2-medium
    on Nov 26, 2026
  4. devops-cli-service commented on Nov 26, 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 (10)

    Tools considered:

    Searches run:

    • github actions template sync delete files removed from template repository, results: 5
    • copier update remove files deleted from template, results: 5
    • copier template update delete files that no longer exist in template, results: 5
    • GitHub REST API git trees sha null removes file tree entry, results: 5
    • copier-org copier, results: 5
    • cruft template update delete obsolete files, results: 5
    • copier.readthedocs.io updating a project deletions, results: 5
    • docs.github.com REST API git trees create a tree, results: 5
    • octokit createTree sha null delete path, results: 5
    • GitHub Git Data API trees, results: 5

    Sources:

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

    @devops-cli-service
    Contributor

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

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 29, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 29, 2026
  9. devops-cli-service commented on Nov 29, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-29 03:13 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/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