Repository navigation
Description
Problem
A command that reads the cluster environment can take it from an infra.repos checkout (resolve_environment in src/devops_cli/k8s/environment.py). It reads the files as they are on disk. It gives no sign when the checkout is behind its upstream branch, is on a topic branch or holds uncommitted changes.
Evidence
On 2026-11-26 the local clone of the environment repository had core.bare=true with a full working tree, and its main branch was 79 commits behind origin/main. No command reported it. The clone was repaired by hand.
After step 17 of the repository switch (#7290), devops-cli holds no environment files, so commands run from this repository read that checkout.
Done when
- A command that takes the tree from an
infra.reposcheckout names the checkout and its branch. - A command that only reads warns when the checkout is behind the upstream branch that it last fetched, or holds uncommitted changes.
- A command that writes to the cluster refuses such a checkout, and the message names the fix.
- The checks use local git data only and make no request.
Alternatives check of 2026-11-26: partly.
Tool: gitpython-developers/GitPython (https://github.com/gitpython-developers/GitPython), BSD-3-Clause, last activity 2026-11-26, maintained.
Reason: Searches surfaced only git libraries, not a stale-checkout checker; GitPython reads the branch, its upstream, ahead/behind counts and dirty or bare state from local data, but the warn and refuse policy is left to us.
Covers:
- Active branch name and its tracking branch from local config
- Ahead and behind commit counts without a network request
- Modified and untracked files in the worktree
- Bare flag, which catches the core.bare=true clone state
Lacks:
- No warn-or-refuse rule for commands that write to the cluster
- No message that names the repair command
- No check aimed at infra.repos environment checkouts
- Runs the git binary rather than reading objects in process
Proposed design
Problem statement
A command reads an environment tree from an infra.repos checkout and takes the files as they are on disk. It gives no sign when the checkout is behind its upstream, on a topic branch, bare or dirty, so a command that writes to the cluster can apply files that are not the upstream state. The core.bare=true state comes from the kube-linter pre-commit hook of the infra repo, which runs git init with GIT_DIR set (dan-petty/homelab#323). The change names the checkout and its branch, warns on a read, and refuses a stale checkout on a write, from local git data only.
Acceptance criteria
Requirement: Checkout and branch on the tree
An environment tree that resolve_environment takes from an infra.repos checkout SHALL carry the checkout path and its active branch.
Scenario: Tree from an infra checkout
- WHEN
resolve_environmenttakes the tree from the checkout of an entry ofsettings.infra.reposwhose branchmainis checked out. - THEN The returned tree names the checkout path and the branch
main.
Requirement: Read warns on a stale checkout
A command that only reads an infra.repos checkout SHALL warn when the checkout is behind the upstream branch that it last fetched.
Scenario: Two commits behind upstream
- WHEN The local branch is two commits behind
origin/mainandresolve_environmentis called with nowriteflag. - THEN It returns the tree and writes to stderr a warning that names the checkout, the branch, the count
2and the fixgit -C <checkout> pull --ff-only.
Requirement: Read warns on a dirty checkout
A command that only reads an infra.repos checkout SHALL warn when the checkout holds uncommitted changes.
Scenario: One modified and one untracked file
- WHEN The checkout holds one modified tracked file and one untracked file and
resolve_environmentis called with nowriteflag. - THEN The warning names the checkout, the branch, the count
2of changed files and the fixgit -C <checkout> stash --include-untracked.
Requirement: Write refuses a stale checkout
A command that writes to the cluster MUST refuse an infra.repos checkout that is behind its upstream or holds uncommitted changes.
Scenario: Write on a stale checkout
- WHEN
resolve_environmentis called withwrite=Truefor a checkout that is two commits behind its upstream. - THEN It raises
ConfigurationErrorwith the keyinfra.repos, and the message names the checkout andgit -C <checkout> pull --ff-only.
Requirement: Bare flag with a worktree
The check MUST treat a checkout with core.bare=true and a worktree as unusable and MUST name git -C <checkout> config core.bare false.
Scenario: Bare clone with a worktree
- WHEN The checkout has
core.bare=trueand its files are on disk, as the evidence of the item records. - THEN A read writes the warning with
git -C <checkout> config core.bare false, and a write raisesConfigurationErrorwith the same text.
Requirement: Local data only
The check MUST read local git data only and MUST make no network request.
Scenario: Unreachable origin
- WHEN The checkout's
originURL ishttps://example.invalid/env.gitand itsorigin/mainref is two commits ahead of the local branch. - THEN The check reports two commits behind, every recorded git call passes
local_read=True, and no request reaches that URL.
Requirement: Writing commands ask for a write tree
Every command that changes the cluster MUST resolve its environment tree with write=True unless it runs as a dry run or a plan.
Scenario: Each writing command on a stale checkout
- WHEN
devops argo cd apps bootstrap-gitops,devops k8s deploy-stack,devops k8s teardown-stack,devops k8s bootstrap,devops k8s ollama prune,devops k8s push-secrets,devops k8s bootstrap-mattermost --push-secretsordevops grafana dashboards syncruns without a dry run or plan on a checkout that is two commits behind its upstream. - THEN Each command exits 1 with the message that names the checkout and
git -C <checkout> pull --ff-only, and no Kubernetes request is recorded.
Requirement: Dry run warns and does not refuse
A dry run or a plan of a writing command MUST warn on a stale checkout and MUST NOT refuse it.
Scenario: Dry run of a writing command
- WHEN
devops argo cd apps bootstrap-gitops --dry-runruns on a checkout that is two commits behind its upstream. - THEN The command prints the warning and exits 0 with its plan.
Existing Tool Considered
GitPython (https://github.com/gitpython-developers/GitPython), BSD-3-Clause, maintained: the alternatives check of 2026-11-26 in the issue body gives the verdict partly, and its block states what the tool lacks. The project records that no module of src/ imports GitPython and every start of git goes through run_subprocess (docs/TESTING.md:84; openspec/changes/archive/2026-10-30-2146-one-git-seam-and-fake/proposal.md:11), and GitPython is not a dependency (pyproject.toml:11). The change therefore reads the branch, upstream, ahead and behind counts, dirty files and bare flag with local git commands through that seam, and builds only the warn-or-refuse policy, the repair messages and the infra.repos scope. Cost: about 2,000 tokens to write the reader, the messages and their tests, about 1,000 tokens a year to keep and fix, and about 4 hours elapsed.
Key questions
- Which open tool reads the branch, the upstream, the ahead and behind counts and the dirty state from local data?: GitPython covers the reads, but the project records that it removed GitPython for one git seam: no module of
src/imports it and every start of git goes throughrun_subprocess(docs/TESTING.md:84). The change reads the facts withgit -C <checkout> ...throughrun_subprocess(..., local_read=True):config --get core.bare,branch --show-current,rev-parse --abbrev-ref --symbolic-full-name @{upstream},rev-list --left-right --count HEAD...@{upstream}andstatus --porcelain. It reusescurrent_branch(src/devops_cli/git/operations.py:282) and the status read behindis_git_clean(src/devops_cli/git/operations.py:464), and it treats a git failure as no check. (best practice) [sources: docs/TESTING.md:84, openspec/changes/archive/2026-10-30-2146-one-git-seam-and-fake/proposal.md:11, src/devops_cli/git/operations.py:282, src/devops_cli/git/operations.py:464, pyproject.toml:11]- Chosen: Local git commands through
run_subprocess. The project records one git seam, the commands are local reads that the git fake records, and the code reusescurrent_branchand the status read. - Rejected: GitPython. The alternatives check names it, but the project removed it: no module of
src/imports it and an invariant test fails one that does (docs/TESTING.md:84). - Rejected: pygit2. It binds libgit2 and needs a compiled library, and it reads git outside the one seam that the invariant test enforces.
- Rejected: dulwich. Pure Python, but it reads git objects outside the process runner seam, and the alternatives check names GitPython.
- Chosen: Local git commands through
- Where does the checkout check run?: In
resolve_environment, on the tree that it takes from an entry ofsettings.infra.repos(src/devops_cli/k8s/environment.py:174). A tree from--k8s-dirgets no check because a person gave that path, and a tree from the profile of the current repository gets none because the command runs in that checkout (src/devops_cli/k8s/environment.py:164). When git cannot read the checkout, the tree is returned with no check, so a folder with a.gitand no repository still resolves. (best practice) [sources: src/devops_cli/k8s/environment.py:151, src/devops_cli/k8s/environment.py:164, src/devops_cli/k8s/environment.py:174]- Chosen: In
resolve_environmentfor aninfra.reposcheckout. One place reads every tree, so each command gets the check and no command can skip it. - Rejected: In each command that reads a tree. Each command repeats the check, and a new command can forget it.
- Rejected: In
_profile_tree._profile_treeholds no settings, so it cannot tell aninfra.reposcheckout from the current repository.
- Chosen: In
- How does a command declare that it writes to the cluster?:
resolve_environmenttakes the keywordwritewith the defaultFalse. The commands that change the cluster passwrite=Trueunless the run is a dry run or a plan:bootstrap-gitops(src/devops_cli/commands/argo.py:413),deploy-stackandteardown-stack(src/devops_cli/commands/k8s/stack_lifecycle.py:1488),k8s bootstrap(src/devops_cli/commands/k8s/bootstrap.py:43),ollama prune(src/devops_cli/commands/k8s/ollama.py:111),push-secrets(src/devops_cli/commands/k8s/cluster_secret_push.py:227),bootstrap-mattermost --push-secrets(src/devops_cli/commands/k8s/mattermost_bootstrap.py:403) andgrafana dashboards sync(src/devops_cli/commands/grafana.py:291).load_cluster_secrets_tabletakes the same keyword for the commands that read the table before they resolve a tree. (best practice) [sources: src/devops_cli/k8s/environment.py:151, src/devops_cli/commands/argo.py:413, src/devops_cli/commands/k8s/stack_lifecycle.py:1488, src/devops_cli/commands/k8s/bootstrap.py:43, src/devops_cli/commands/k8s/ollama.py:111, src/devops_cli/commands/k8s/cluster_secret_push.py:227, src/devops_cli/commands/k8s/mattermost_bootstrap.py:403, src/devops_cli/commands/grafana.py:291]- Chosen: A
writekeyword onresolve_environment. The refusal happens where the tree is read, before the command uses a file of the tree. - Rejected: A second function
resolve_writable_environment. It copies the resolution logic, and two names for one tree invite a wrong call. - Rejected: A
require_fresh()method that each writer calls. A writer can forget the call, and the stale tree then reaches the cluster.
- Chosen: A
- How does a read show the warning?:
resolve_environmentcallsprint_warning(<message from ERRORS.k8s>, prefix=False, to_stderr=True)fromdevops_cli.output.console; a test asserts the text on stderr. No module of the project callswarnings.warn, and the project's design of 2026-11-26 returns a warning text and prints it withprint_warning(openspec/changes/archive/2026-11-26-7233-a-new-worktree-gets-the-pinned/design.md:9). Here the one place that resolves the tree prints it, so no command can forget it, and stderr keeps stdout whole for--format json. (best practice) [sources: src/devops_cli/output/console.py:447, openspec/changes/archive/2026-11-26-7233-a-new-worktree-gets-the-pinned/design.md:9, src/devops_cli/commands/k8s/catalog.py:85, src/devops_cli/k8s/environment.py:151]- Chosen:
print_warningwithto_stderr=True. The project's leveled warning printer shows it on stderr, a test catches the text, and stdout stays parseable. - Rejected:
warnings.warn. No module of the project uses it, and Python's default filter shows one warning per location. - Rejected: A field on the tree that each command prints. Each command needs print code, and a command that forgets prints nothing.
- Chosen:
- Where do the checkout messages live?: New keys under
ERRORS.k8s, next toenvironment_path_missingatsrc/devops_cli/lang/en/errors.py:235, and the refusal raisesConfigurationErrorwith the keyinfra.repos, asenvironment_root_ambiguousdoes atsrc/devops_cli/k8s/environment.py:184. [sources: src/devops_cli/lang/en/errors.py:235, src/devops_cli/k8s/environment.py:184] - Which repair command does each state name?: A checkout behind its upstream names
git -C <checkout> pull --ff-only, the command that the bootstrap procedure already gives (k8s/README.md:454). A dirty checkout namesgit -C <checkout> stash --include-untracked, because the count includes untracked files and plaingit stashleaves them. A checkout withcore.bare=trueand a worktree namesgit -C <checkout> config core.bare false, the repair that the issue records. (best practice) [sources: k8s/README.md:454, src/devops_cli/git/operations.py:464, openspec/changes/archive/2026-11-12-5265-github-token-scope/design.md:12]- Chosen: One fix per state, in the message. The message gives the exact command, and the reader repairs the checkout with no search.
- Rejected: A pointer to the repository documentation. The reader leaves the command to find the steps, and the checkout stays stale.
- Rejected: No fix in the message. The message states a problem with no action.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 26, 2026
5131 created the infra.repos checkout reading path; the candidate adds safety warnings and refusals to that same path, a different change.dan-petty commentedon Nov 26, 2026
Cause of the
core.bare=truestate of the environment clone, found on 2026-11-26: the pre-commit hookkube-linter (make k8s-lint)of dan-petty/homelab, run from a linked worktree. kube-linter runsgit initfor a remote kustomize base, and inside the hook that command inheritsGIT_DIRand changes the clone. Reproduction and fix criteria: dan-petty/homelab#323. The clone flipped again today after a commit belowk8s/and was repaired withgit config core.bare false.devops-cli-service commentedon Nov 26, 2026
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:
Sources:
devops-cli-service commentedon Nov 28, 2026
Next step: the stage job writes the plan of the item. See the section Proposed design of the body.
devops-cli-service commentedon Nov 29, 2026
Released in v0.243.1: https://github.com/dan-petty/devops-cli/releases/tag/v0.243.1
devops-cli-service commentedon Nov 29, 2026
Live since 2026-11-29 03:13 UTC
fix(k8s): remove stale environment checkout check (#7784)