Skip to content

wip init stops reading a failed git status as clean, refuses a template path whose ancestor is a symlink or not a directory, refuses one staged at a mode it never wrote, and names a skip-worktree path HEAD carries and the disk does not - #101

Merged
brettheap merged 11 commits into
mainfrom
fix/wip-init-step7-ancestors-modes-sparse-and-status-failure
Sep 16, 2026

Conversation

@brettheap

@brettheap brettheap commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Four hardening gaps in openRepoTools wip init's step 6a and step 7, each with a regression test that fails before the change and passes after it. Nothing in step 8's push is touched (#64 is a design question the lane owner has put to Brett Heap), and step 6a keeps its --untracked-files=all / :(exclude)<template path> shape.

#49 — a git status this command could not run was read as a clean checkout

Step 6a is the gate that refuses an ADOPTED checkout carrying anything this command did not write, asked BEFORE step 7 writes a byte for exactly that reason. It asked the question as git … status … 2>/dev/null | sed … || :: the redirect threw away git's own diagnostic, and the || : turned any non-zero exit of the pipeline — under this file's set -o pipefail, git status's own: a corrupt index, an unreadable .git, a submodule error — into a plain empty string, which is exactly what a clean checkout produces. So a checkout this command could not even PUT the question to passed the gate and step 7 seeded into it.

The run goes through wip_quietly now, so the refusal carries git's own words under What it said: the way the clone and the seed commit already do, and the change list is read from the file that wrapper writes — [ -s "$WIP_LAST_OUT" ] decides, never a capture a failure can empty. wip_quietly keeps its stdout in $WORKDIR/cmd-out instead of /dev/null for that; nothing ever prints it, so stdout is still dropped from the report, and a command whose OUTPUT is the answer runs through the one wrapper rather than carrying a second copy of its stderr capture.

#62 — the leaf was asked about and its ancestors were not

path_kind asks what is at $rel itself; nothing asked what is at handoffs, lanes, lanes/log or workspaces. An adopted checkout can carry a TRACKED symlink at one of those, and step 6a reads that worktree as clean because it IS what HEAD says. Every test step 7 makes then answers as though nothing were at handoffs/README.md at all — [ -e ] and [ -L ] are false where the link's target holds no such file, and git has no notion of a path inside a tracked symlink, so :$rel, HEAD:$rel and ls-files -u are false too. The MISSING branch was reached, its mkdir -p created nothing (the link resolves to a directory that is already there) and its cp wrote this run's template bytes THROUGH the link, outside the checkout. Only the git add two steps later noticed — fatal: … is beyond a symbolic link — after the bytes had landed.

Every component between $checkout and the leaf is now walked left to right before any branch acts, and a symlink at one of them is a refusal naming the component and the path it points to, with nothing written. The same walk answers an ancestor that is not a directory at all, because the same MISSING branch meets it one line earlier: a regular file committed at handoffs fails that mkdir -p, and a failing mkdir under this file's set -e exits 1 — the code this toolset spends on "findings were printed" — from a run that meant to refuse with 2 and never said why. One walk, one comment, both refusals tested. (unusable_dir_kind is not this question and so is not reused: it climbs UP to the nearest ancestor that exists and asks whether a file can be created there, so a symlink to a directory that is really there answers it -d/-w/-x — usable — and it never looks at the components below. This walk goes DOWN the exact relative path and asks what each component IS.)

#63 — the index check compared the blob and never the staged mode

cat-file -p prints a blob's BYTES and never its mode, so a path a person had staged with git add --chmod=+x, byte-identical to the template and executable, read as "the index carries the template". Step 8's git add then restaged it from the WORKTREE at the worktree's own mode and committed: their 100755 replaced by 100644 without a word. git ls-files -s -- "$rel"'s first field is asked for now and must be 100644 — the only mode any file in templates/workspace-root carries and the only mode this command has ever written.

The arm chosen is REFUSE, naming the mode and the path, because that is the contract of the branch it sits in: every other "this is not an earlier run's own leftover" answer there is a die — a symlink, a FIFO, a staged addition with no worktree file, an unresolved conflict, bytes that are not the template's — and the one arm that succeeds means "this IS my own leftover, carry it into the seed commit". Leaving it and counting it as the person's would be worse than either: the path would be neither seeded nor owed, so step 8 would commit and push without it and step 9 would write the pointer file over a main missing a template file — the state step 8's own comment says no later run digs out of. A mode this command could not READ is refused the same way, since an unreadable answer is never a matching one. The check is asked BEFORE the fetch, with the branch's other local questions, so a machine with no network gets the refusal that names the real reason.

#69 — a skip-worktree entry could not be told from a real tracked file

skip-worktree — which is also what git sparse-checkout sets — tells git not to compare the worktree at that path at all: HEAD carries it, the stage-0 entry carries it, git status is clean, and the file is physically absent. That answered step 7's outer presence test exactly as a person's own deliberate git rm does, so the run continued past it, counted it as neither seeded nor owed, printed "the workspace already carries every template file" and wrote the pointer file — while a template path this command seeds, and the lane tooling reads, was not on disk.

The arm chosen is to NAME it and write nothing. The principle the branch is built on still stands — a template path HEAD already carries is the person's, and this command has never modified a committed file — so seeding over it is out; and a refusal would stop a run whose only problem is one line a person needs to read. What it stops being is INVISIBLE: git ls-files -v -- "$rel" is asked where the worktree file is absent, and one line in the summary says HEAD carries it, the index marks it skip-worktree, and it is not on disk, with the git update-index --no-skip-worktree that brings it back. Exit stays 0 and the run finishes.

Two notes on the tag letter, since the issue body has it the other way round: ls-files -v prints S for skip-worktree, and lowercase is what it uses for assume-unchanged (so s is skip-worktree and assume-unchanged, and both are matched). h — assume-unchanged alone — is deliberately not claimed as this case: that bit is a person telling git to stop stat-ing a path they own and keep on disk, not a checkout that never materialized one, and calling it "skip-worktree" in the summary would be false.

Round 2 — Copilot

  • A tracked submodule at a template path's ancestor (thread) — taken, and reproduced end to end first. A gitlink at handoffs passes both questions the new walk asked (-L false, -d true of a whole repository on disk); a clean submodule reports nothing to step 6a; and a gitlink carries no handoffs/README.md, so every presence test in step 7 is false. The MISSING branch wrote this run's template bytes INSIDE that nested repository and the git add two steps later answered fatal: Pathspec 'handoffs/README.md' is in submodule 'handoffs' — with the bytes already there. The walk now asks the INDEX at that exact component (ls-files -s's path column, refused on 160000), because the index is what makes it a submodule and a deinited one is an empty directory with no .git in it at all — and it asks .git beside that, for a nested repository nobody tracked. Regression: test_a_submodule_at_a_template_paths_ancestor_is_refused[checked-out|deinitialized].

Round 3 — Copilot

  • cat-file -e ":$rel" conflates "no index entry" with "entry whose blob is lost" (thread) — taken, and measured first: with the staged blob removed, cat-file -e answers false while ls-files -s still carries the entry, and git add then replaces the person's staged sha silently. Presence is git ls-files -s's answer now (the index, never the object store, at the exact path and stage 0); a read that FAILS is a refusal rather than an empty index, an entry whose blob cannot be read gets its own refusal, and the comparison's "no entry" arm is spelled [ -z "$staged_mode" ] so a failed object lookup can no longer reach it. Regression: test_a_staged_entry_whose_blob_is_gone_is_refused_not_read_as_no_entry.

Filed rather than fixed here

How it was tested

tests/run.sh -k "wip_init_command or repo_hygiene" on Linux, twice: once with the four fixes reverted, where the five new cases fail and nothing else does, and once with them in place, where the whole of both modules passes. The four new tests are

  • test_a_git_status_this_command_cannot_run_is_refused_not_read_as_clean — corrupts .git/index in an adopted checkout that is missing one template file (rev-parse still answers, so the run reaches step 6a) and asserts exit 2 and git's own fatal: line about the index under What it said: (the exact sentence is not pinned — which one a corrupt index draws depends on how it is corrupt and on the git version; this run's was fatal: .git/index: index file smaller than expected), and that the missing template file was still not written.
  • test_an_ancestor_of_a_template_path_that_is_not_a_directory_is_refused[symlink|regular-file] — commits each shape at handoffs and asserts exit 2, the component and its target in the refusal, nothing staged, no commit, no push, and — for the link — that the directory it points at is still empty.
  • test_a_template_path_staged_at_another_mode_is_refused_not_restaged — stages the template's own substituted bytes at handoffs/README.md with --chmod=+x (which moves the index and leaves the worktree file at 0644, so only the mode differs) and asserts the person's staged 100755 is still there after the refusal.
  • test_a_skip_worktree_template_path_is_named_and_never_seeded — sets the bit on lanes/LANES.md, deletes the file, asserts git status really is silent about it, then asserts the summary line, exit 0, nothing written, nothing staged, no commit and no push for it.

Everything new parses under macOS bash 3.2 — no ${x,,}, mapfile, declare -A or local -n; the ancestor walk is a case/while over ${rest%%/*} and ${rest#*/}, the one case whose word is a command substitution was hoisted onto its own line, and the new sed spells -- before its operand. CI runs the whole suite on all four jobs.

Round 1 — Copilot, and SonarCloud's gate

  • The worktree's own mode, beside the index's (thread) — taken. wip init's owed-candidate index check compares blob content but never the staged mode #63's fix asks what the INDEX carries at an owed candidate, and step 8 stages from the WORKTREE, so a candidate carrying the execute bit is recorded as 100755 in the seed commit and pushed. Two routes reach that point which the stage-0 question never sees: an UNTRACKED template path whose bytes match the template and whose file somebody chmod'ed, and a path staged 100644 whose worktree file got the bit afterwards — step 6a catches neither, because it excludes the template's own paths by name. This command copies the template's bytes from a 0644 file and has never chmod'ed anything it wrote, so an executable file there is somebody's own and gets the same refusal a staged 100755 gets. Regression: test_an_executable_template_path_is_refused_not_seeded_at_100755[untracked|staged-then-chmod]. The refusal reads core.fileMode (as a boolean, because git spells false four ways) and stands down only for an explicit false: on a filesystem that reports every file executable git stages 100644 regardless, and refusing there would refuse every re-run on that mount over a bit that means nothing.
  • sed -e 'script' -- "$file" on BSD sed (thread) — declined, with the cited file as the evidence. _end_of_options_after_an_operand's own docstring names this shape as the REMEDY rather than the defect — "sed -n -e 'script' "$file" has no operand before the file list at all, which is why that is the shape this repository uses" — the checker itself does not flag the line (-e is in _OPTIONS_WITH_ARGUMENTS, so its argument is not an operand and -- is reached with seen_operand false), and lanes-edit.sh:1387 already ships the identical shape (grep -n -e … -e … -- "$file") through the macOS job. BSD's getopt(3) consumes --; what it does not do is permute, which is why a bare script operand before -- breaks there and an -e script does not.
  • SonarCloud's new-code duplication gate (4.0% against a 3% threshold) — one ten-line fixture block written out three times, two of those copies predating this branch and the third arriving with wip init's owed-candidate index check compares blob content but never the staged mode #63's test. adopted_checkout_without is that block once, with four callers.
  • SonarCloud python:S9073 — the step 6a test's one composite assertion split into the two separate claims it was making.

Closes #49
Closes #62
Closes #63
Closes #69

Lane: openRepoTools-1

🤖 Generated with Claude Code

Summary by Sourcery

Harden wip init against ambiguous repository state and unsafe template paths before it writes, stages, commits, or reports completion.

Bug Fixes:

  • Prevent failed git status checks from being interpreted as a clean checkout during wip init.
  • Refuse template paths beneath symlink, non-directory, or submodule ancestors before writing through them.
  • Refuse staged template entries with unsupported modes or unreadable staged blobs instead of silently replacing them.
  • Report missing skip-worktree template paths while leaving them untouched and allowing the run to complete.

Enhancements:

  • Consolidate adopted-checkout test setup and expand regression coverage for wip init safety cases.

CI:

  • Verify the expanded regression suite across the project’s CI jobs and maintain compatibility with macOS Bash 3.2.

Tests:

  • Add regression tests covering failed git status, unsafe ancestors, missing staged blobs, submodules, executable modes, staged mode mismatches, and skip-worktree paths.

brettheap and others added 4 commits September 16, 2026 05:40
…s empty output as a clean checkout (#49)

`wip init`'s step 6a is the gate that refuses an ADOPTED checkout carrying
anything this command did not write, and it is asked BEFORE step 7 writes a
byte for exactly that reason. It asked the question as

    unrelated="$(git -C "$checkout" "${status_args[@]}" 2>/dev/null | sed … || :)"

The `2>/dev/null` threw away git's own diagnostic and the `|| :` turned any
non-zero exit of the pipeline — under this file's `set -o pipefail`, `git
status`'s own: a corrupt index, an unreadable `.git`, a submodule error — into
a plain empty string. An empty change list is precisely what "nothing
unrelated, proceed" looks like, so a checkout this command could not even PUT
the question to was read as clean and step 7 seeded into it, past the one gate
that exists to refuse first.

The run is `wip_quietly`'s now, so the failure carries git's own words under the
refusal the way the clone and the seed commit already do, and the change list is
read from the file that wrapper writes rather than from a capture a failure can
empty: `[ -s "$WIP_LAST_OUT" ]` decides, never a variable. `wip_quietly` keeps
its stdout in `$WORKDIR/cmd-out` instead of `/dev/null` for that — nothing ever
prints it, so stdout is still dropped from the report — which is what lets a
command whose OUTPUT is the answer run through the one wrapper rather than
carrying a second copy of its stderr capture. The `--untracked-files=all` and
`:(exclude)<template path>` shape is unchanged.

The regression test
`test_a_git_status_this_command_cannot_run_is_refused_not_read_as_clean`
corrupts `.git/index` in an adopted checkout that is
missing one template file — `rev-parse` still answers, so the run reaches step
6a — and asserts exit 2, git's own `fatal:` line about the index under
`What it said:`, and that the missing template file was still not written.
(The sentence itself is not pinned: which one a corrupt index draws depends
on how it is corrupt and on the git version.)

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…r anything else that is not a directory, before `mkdir -p` and `cp` write through it (#62)

`path_kind` asks what is at `$rel` itself; nothing asked what is at `handoffs`,
`lanes`, `lanes/log` or `workspaces`. An adopted checkout can carry a TRACKED
symlink at one of those — a person whose `handoffs` is a link into another tree
of their own, committed — and step 6a reads that worktree as clean, because it
IS what HEAD says. Every test step 7 then makes answers as though nothing were
at `handoffs/README.md` at all: `[ -e ]` and `[ -L ]` are false where the link's
target holds no such file, and git has no notion of a path inside a tracked
symlink, so `:$rel`, `HEAD:$rel` and `ls-files -u` are false too. The MISSING
branch was reached, its `mkdir -p` created nothing (the link resolves to a
directory that is already there) and its `cp` wrote this run's template bytes
THROUGH the link — outside the checkout, where the link led. Only the `git add`
two steps later noticed, with `fatal: … is beyond a symbolic link`, after the
bytes had landed somewhere this command was never pointed at.

So every component of `$rel` between `$checkout` and the leaf is walked first,
left to right, and a symlink at any of them is a refusal naming the component
and the path it points to, with nothing written. The walk answers an ancestor
that is not a directory at all in the same breath, because the same MISSING
branch meets it one line earlier: a regular file committed at `handoffs` fails
that `mkdir -p`, and a failing `mkdir` under this file's `set -e` exits 1 — the
code this toolset spends on "findings were printed" — from a run that meant to
refuse with 2 and never said why.

The regression test
`test_an_ancestor_of_a_template_path_that_is_not_a_directory_is_refused`
commits each shape at `handoffs` in an adopted
checkout and asserts exit 2, the component and its target in the refusal,
nothing staged, no commit, no push — and, for the link, that the directory it
points at is still empty.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e blob, and a template path staged at any mode but 100644 is refused (#63)

Step 7's owed-candidate branch trusted the index the moment its blob matched the
fetched template, and `cat-file -p` prints a blob's BYTES and never its mode. So
a path a person had staged with `git add --chmod=+x`, byte-identical to the
template and executable, read as "the index carries the template": step 8's
`git add` then restaged that path from the WORKTREE at the worktree's own mode
and committed it, replacing their `100755` with `100644` without a word.

`git ls-files -s -- "$rel"`'s first field is asked for now, and it must be
`100644` — the only mode any file in `templates/workspace-root` carries, and the
only mode this command has ever written, having never chmod'ed anything.

THE ARM IS A REFUSAL, not "leave it and count it as the person's", because that
is the contract of the branch it sits in: every other "this is not an earlier
run's own leftover" answer there is a `die` — a symlink, a FIFO, a staged
addition with no worktree file, an unresolved conflict, bytes that are not the
template's — and the one arm that succeeds means "this IS my own leftover, carry
it into the seed commit". Leaving it would be worse than either: the path is
neither seeded nor owed, so step 8 commits and pushes without it and step 9
writes the pointer file over a main that is missing a template file, which is
the state no later run digs out of. A mode this command could not READ is
refused the same way, because an unreadable answer is never a matching one. It
is asked BEFORE the fetch, with the branch's other local questions: the answer
does not depend on the template's bytes, and a machine with no network deserves
the refusal that names the real reason.

The regression test
`test_a_template_path_staged_at_another_mode_is_refused_not_restaged` stages
the template's own substituted bytes at
`handoffs/README.md` with `--chmod=+x` (which moves the index and leaves the
worktree file at 0644, so only the mode differs) and asserts exit 2, the mode
and the path in the refusal, and that the person's staged `100755` is still
there afterwards.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… named in the summary rather than silently passed (#69)

`skip-worktree` — which is also what `git sparse-checkout` sets — tells git not
to compare the worktree at that path at all: HEAD carries it, the stage-0 entry
carries it, `git status` is clean, and the file is physically absent. That
answered step 7's outer presence test exactly as a person's own deliberate
`git rm` does, so the run `continue`d past it, counted it as neither `seeded`
nor `owed`, printed "the workspace already carries every template file" and
wrote the pointer file — while a template path this command seeds, and the lane
tooling reads, was not on disk at all.

THE ARM IS TO NAME IT, and to write nothing. The principle the branch is built
on still stands — a template path HEAD already carries is the person's, and this
command has never modified a committed file — so seeding over it is out, and a
refusal would stop a run whose only problem is one line a person needs to read.
What it stops being is INVISIBLE: `git ls-files -v -- "$rel"` is asked where the
worktree file is absent, and a tag of `S` (or the lowercase `s` that means the
same entry is also assume-unchanged) puts one line in the summary saying HEAD
carries it, the index marks it skip-worktree, and it is not on disk, with the
`git update-index --no-skip-worktree` that brings it back. `h` — assume-
unchanged alone — is deliberately not claimed as this case: that bit is a person
telling git to stop stat-ing a path they own and keep, not a checkout that never
materialized one.

(The issue's body says a LOWERCASE letter marks skip-worktree. `ls-files -v`
prints `S`; lowercase is what it uses for assume-unchanged, whatever the letter,
so both spellings of a skip-worktree entry are matched and `h` is not.)

The regression test
`test_a_skip_worktree_template_path_is_named_and_never_seeded` sets the bit on
`lanes/LANES.md`, deletes the file, asserts
that `git status` really is silent about it, and then asserts the line, exit 0,
nothing written at the path, nothing staged, no commit and no push for it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 16, 2026 05:42

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 20 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 16, 2026

Copy link
Copy Markdown

Reviewer's Guide

Hardens wip init around four adopted-checkout edge cases: Git status failures now refuse safely with diagnostics, unsafe template-path ancestors are rejected before writes, staged mode mismatches are refused, and absent skip-worktree files are explicitly reported without being seeded. Regression coverage verifies refusal, non-mutation, and successful completion semantics.

File-Level Changes

Change Details Files
Hardened wip init step 6a so failures from git status are surfaced as refusals instead of being treated as a clean checkout.
  • Run status through wip_quietly while retaining command output for diagnostics.
  • Refuse when the command produces no usable change list because Git failed, and include Git's stderr under What it said:.
openRepoTools
tests/test_wip_init_command.py
Added validation of every ancestor component of each template path before step 7 writes anything.
  • Walk path components from the checkout root to the template leaf.
  • Refuse tracked symlink ancestors with their target and refuse ancestors that are not directories.
  • Verify no files are staged, committed, pushed, or written for these refusal cases.
openRepoTools
tests/test_wip_init_command.py
Made staged-template detection validate the index mode as well as blob contents.
  • Read the stage-0 mode with git ls-files -s.
  • Accept only the 100644 mode written by the command and refuse other modes without restaging or committing them.
openRepoTools
tests/test_wip_init_command.py
Made absent skip-worktree template paths visible without seeding or failing the run.
  • Detect uppercase and lowercase skip-worktree tags from git ls-files -v, while excluding assume-unchanged-only entries.
  • Report that HEAD carries the path, the index marks it skip-worktree, and the file is absent.
  • Leave exit status successful and complete the pointer-file workflow without writes, staging, commits, or pushes.
openRepoTools
tests/test_wip_init_command.py

Assessment against linked issues

Issue Objective Addressed Explanation
#49 Ensure that a failure running the step 6a git status safety check is treated as a refusal rather than as an empty, clean change list, while preserving the existing untracked-file and template-exclusion arguments and reporting Git's diagnostic. ✅
#62 During wip init step 7, inspect every ancestor component of a template path between the checkout root and the leaf, and refuse before writing if any ancestor is a symlink. ✅
#62 Prevent template seeding from traversing an ancestor that exists but is not a directory, while reporting a clear refusal instead of allowing mkdir or cp to fail or write outside the checkout. ✅
#63 Update wip init step 7's owed-candidate index check to verify both the staged blob content and the staged file mode, refusing to proceed when the index mode differs from the template's expected 100644 mode. ✅
#69 Detect when a template path carried by HEAD is marked skip-worktree or sparse-checkout, absent from the worktree, and would otherwise be mistaken for a fully present tracked file. ✅
#69 Make wip init explicitly report the missing skip-worktree template path without seeding, staging, committing, pushing, or writing an incorrect workspace pointer, while preserving the command's existing ownership principle and successful exit behavior. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A moderate macOS portability issue and a critical mode-validation gap remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Hardens wip init against failed status checks, unsafe template ancestors, staged mode mismatches, and missing skip-worktree files.

Changes:

  • Adds safety checks and diagnostics in openRepoTools.
  • Adds regression coverage in tests/test_wip_init_command.py.
  • Remaining findings: macOS-incompatible sed argument ordering and incomplete worktree mode validation.
File summaries
File Summary
tests/test_wip_init_command.py Adds regression tests for the four hardening cases.
openRepoTools Implements validation and reporting changes; requires fixes for the noted findings.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread openRepoTools Resolved
Comment thread openRepoTools Resolved
brettheap and others added 4 commits September 16, 2026 05:47
…late path in share one fixture instead of a copy each (SonarCloud's new-code duplication gate on #101)

`adopted_checkout_without` is the ten lines four of them had written out
separately: the adopted checkout, the template's own substituted bytes read
BEFORE the path is removed (they are what an earlier run's leftover looks
like), the `git rm` + commit + push that takes it out of HEAD — step 7 asks
`HEAD:$rel` first, so a path HEAD still carries never reaches that branch at
all — and the HEAD every refusal is then checked against.

Two of those copies predate this branch and the third arrived with #63's
regression test, which is what took SonarCloud's `new_duplicated_lines_density`
to 4.0% against a 3% gate: one ten-line block, three times. #49's test takes the
same fixture for the one thing it needs from it — a template file that is
genuinely missing — and ignores the bytes. A copy per test is also how two of
them come to differ in a way nobody meant,
which is the same argument this repository makes about two copies of one rule
in the code itself.

No test's behaviour changes: the commit message the fixture writes now names
the path it removed rather than spelling `handoffs/README.md` in prose, and
nothing asserts on it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…able template path is refused rather than staged into the seed as 100755 (Copilot round 1 on #101)

#63's fix asks what the INDEX carries at an owed candidate, and step 8 stages
from the WORKTREE — so the half that decides what actually lands in the seed
commit was still unasked. An owed candidate whose file carries the execute bit
is recorded as `100755` and pushed to the workspace repository's `main`, and it
reaches that point two ways the stage-0 question never sees: an UNTRACKED
template path whose bytes match the template and whose file somebody chmod'ed,
and a path staged `100644` whose worktree file got the bit afterwards. Step 6a
cannot catch either, because it excludes the template's own paths by name.

This command copies the template's bytes from a 0644 file — `cp` from the
pinned checkout, or a shell redirect, then `sed` into `$file.subst` and a
`mv` — and has never chmod'ed anything it wrote. So an executable file at a
template path is not an earlier run's leftover whatever its bytes say; it is
somebody's own, and this branch's answer to that is the refusal the staged mode
already gets.

ASKED ONLY WHERE GIT WOULD RECORD IT. On a filesystem that reports every file
executable, `git clone` sets `core.fileMode=false` and git stages `100644`
regardless; refusing there would refuse every re-run on that mount over a bit
that means nothing, so the config that decides it is read and only an explicit
`false` stands the refusal down (unset is true).

`test_an_executable_template_path_is_refused_not_seeded_at_100755` covers both
shapes: without this commit each exits 0, seeds, commits and pushes; with it
each is exit 2 naming the path, with the person's own 0755 and their staged
100644 untouched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…re says which half was missing (SonarCloud python:S9073 on #101)

`assert "fatal:" in stderr and "index" in stderr` is one assertion carrying two
claims, and the two say different things: the first is that git's own sentence
reached the person at all, the second that the sentence is about the index it
could not read. Failed together they name neither, which is the whole of what
S9073 is about — and this suite's own convention is a message per claim.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ad as a BOOLEAN, because git spells false four ways

`git config --get core.fileMode` hands back whatever is written in the file, and
git's own boolean is `false`, `no`, `off` or `0` — so a checkout carrying
`fileMode = 0`, which is what some tools write, answered `0`, which is not the
string `false`, and the refusal stood where git would in fact have staged
`100644`. `--bool` is git's own normalisation of exactly that set, and it is
older than every git this toolset runs under.

Unset still answers 1 and nothing, which is still not `false`, so the refusal
still stands there: an answer this command could not get is never permission to
publish a mode.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings September 16, 2026 05:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical issue and additional unresolved findings remain.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (3)

openRepoTools:2135

  • This else is the false arm of the outer presence test at lines 1927–1930, so it runs only when neither the worktree, index, HEAD, nor a conflict entry exists. A skip-worktree path still has a HEAD entry and a stage-0 index entry, so it takes the then arm, if ! HEAD is false, and continues without evaluating ls-files -v; the new regression therefore cannot report the missing file. Move this probe into the outer then path when HEAD carries the path but the worktree is absent, while leaving the outer else to reach normal missing-file seeding.
			else
				# ---- A PATH HEAD CARRIES THAT IS NOT ON DISK BECAUSE THE INDEX
				# SAYS SO IS NAMED, NOT SEEDED AND NOT SILENTLY PASSED (#69).
				#
				# `skip-worktree` — which is also what `git sparse-checkout`

openRepoTools:2197

  • The only recovery command printed for this finding is incomplete: the output ends with git update-index --no-skip-worktree -- and puts that path on a separate prose line, without naming the checkout or the actual template path. A user cannot copy it to restore the reported entry, especially when wip init was run outside the checkout. Print a complete command such as git -C "$checkout" update-index --no-skip-worktree -- "$rel" (or clearly mark both values as placeholders).
		say "      (a sparse checkout leaves a tracked path there and off the disk; nothing"
		say "       was written or committed at it. \`git update-index --no-skip-worktree --\`"
		say "       that path, or \`git sparse-checkout\`, is what brings it back.)"

openRepoTools:2197

  • The recovery command printed here only clears the index bit; git update-index --no-skip-worktree -- <path> does not recreate a missing worktree file. After following this message, the path is still absent and step 6a will report it as a deletion, so the documented remedy cannot get the checkout back to a runnable state. Include a checkout/restore step (or an explicit sparse-checkout reapply) after clearing the bit.
		say "       was written or committed at it. \`git update-index --no-skip-worktree --\`"
		say "       that path, or \`git sparse-checkout\`, is what brings it back.)"
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread openRepoTools Resolved
…— a submodule, or a clone somebody left there — is refused before the `cp` writes inside it (Copilot round 2 on #101)

The ancestor walk added for #62 asks whether each component is a symlink and
whether it is a directory, and a tracked SUBMODULE passes both: `-L` is false
and `-d` is true, because a gitlink at `handoffs` is a whole repository on disk.
Nothing else catches it either — a clean submodule reports nothing to step 6a,
and a gitlink carries no `handoffs/README.md`, so `[ -e ]`, `[ -L ]`, `:$rel`,
`HEAD:$rel` and `ls-files -u` are all false. The MISSING branch then wrote this
run's template bytes INSIDE somebody's nested repository, and the `git add` two
steps later answered

    fatal: Pathspec 'handoffs/README.md' is in submodule 'handoffs'

with the bytes already there, in a repository this command has no business in
and does not clean up. Measured on a real submodule, both before and after.

THE INDEX IS WHAT MAKES IT A SUBMODULE, so that is what is asked: `ls-files -s`
answers `160000` at that exact path whether or not the submodule is checked
out, and a `deinit`ed one — an EMPTY directory with no `.git` in it at all —
fails the same `git add` for the same reason. The `.git` test beside it catches
the other shape, a nested repository nobody tracked, which an ignore rule can
hide from step 6a as well. `$4` is `ls-files -s`'s path column and every
component walked here comes from `$WIP_TEMPLATE_FILES`, nine fixed ASCII paths,
so it is never a quoted or split field.

`test_a_submodule_at_a_template_paths_ancestor_is_refused[checked-out|
deinitialized]` builds a real submodule with `protocol.file.allow=always` (git
has refused a local-path submodule without it since 2.38), asserts `git status`
really is silent about it, and then asserts exit 2 naming the component, with
nothing written inside the nested repository, nothing staged, no commit and no
push.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings September 16, 2026 06:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved correctness and reporting issues remain in openRepoTools, including staged-entry detection, executable-mode detection, recovery guidance, and the clone-failure write guarantee.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (3)

Previously missed (1) — in code that hasn't changed since the last review.

openRepoTools:2232

  • The recovery command printed here is incomplete: git update-index --no-skip-worktree -- has no path operand, so copying the command fails and the path is only mentioned outside the backticks. Include $rel in the command and give the sparse-checkout alternative as an actionable pattern change.

openRepoTools:2087

  • [ -x ] tests whether the effective user can execute the file, not whether the mode bit Git records is executable. An adopted/shared checkout can have the owner execute bit set while the current user lacks execute access, so this condition passes even though git add records mode 100755 and publishes a mode this command never wrote. Inspect the file's mode bit directly, using a portable approach for the supported platforms, rather than an access check.
				if [ -x "$checkout/$rel" ] &&
					[ "$(git -C "$checkout" config --bool --get core.fileMode 2>/dev/null || :)" != "false" ]
				then

openRepoTools:1841

  • This refusal is also used immediately after a fresh gh repo clone (step 6 runs before this gate), so the clone has already written files into $checkout when git status fails. Saying that nothing was written is false in that path; limit the guarantee to step 7's template writes so the refusal reports the checkout state accurately.
    it could not put that question to. NOTHING was written into that checkout on this run
    and nothing was staged.
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread openRepoTools Resolved
…n entry whose blob git has lost is a refusal rather than an empty index (Copilot round 3 on #101)

`git cat-file -e ":$rel"` answers false in TWO states, because it resolves the
name through the index and then looks the OBJECT up: there is no stage-0 entry,
or there is one whose blob the object store has lost. The staged-mode guard
gated on it and the comparison below took its "no entry" arm on the same
question, so the second state was spent as though it were the first — the mode
was never checked, a worktree that reads back as the template was accepted as
this command's own leftover, and step 8's `git add` replaced what the person
had staged with this run's copy. Measured on a repository with the blob
removed: the staged sha changes and the `add` reports nothing.

`git ls-files -s` reads the index and never the object store, so presence is
its answer now, at the exact path and at stage 0. Three states, three answers:
a read that FAILS is a refusal and never an empty index (#49's own lesson, one
question over); an entry whose blob cannot be read is a refusal of its own,
because an entry this command cannot READ is not one it may stage over; and no
entry at all is the arm the comparison already had.

`test_a_staged_entry_whose_blob_is_gone_is_refused_not_read_as_no_entry` stages
somebody's own edit, makes the worktree read back as the template, deletes the
object behind the index entry, and asserts exit 2 with the person's staged sha
still in `ls-files -s` afterwards. Without this commit the run exits 0 and
replaces it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings September 16, 2026 06:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The skip-worktree remediation command is malformed and omits the affected path.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

openRepoTools:2266

  • The skip-worktree remediation renders an unusable command: it has a closing backtick without an opening one, and -- is not followed by the affected path. A user copying git update-index --no-skip-worktree -- gets Git's empty-pathspec error; include $rel in the command and balance the quoting.
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 16, 2026 10:22
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Two moderate correctness issues and one documentation nit remain in openRepoTools.

Review details

Suppressed comments (3)

openRepoTools:2345

  • The recovery command in this summary is printed without a path operand: git update-index --no-skip-worktree -- exits with a usage error. Include the affected $rel in the command (and keep the sparse-checkout alternative as prose) so the only remediation shown for this case is runnable.
		say "       was written or committed at it. \`git update-index --no-skip-worktree --\`"
		say "       that path, or \`git sparse-checkout\`, is what brings it back.)"

openRepoTools:2215

  • This new ls-files -s guard is reached only after the outer presence test at line 2042. If a stage-0 entry's blob is missing and the worktree file is also absent, cat-file -e :$rel in that outer test fails, so execution skips this block and reaches the MISSING branch, which recreates the file and lets git add replace the person's index entry instead of refusing. Make the outer presence check use index metadata (and handle a failed read) so every stage-0 entry reaches this validation.
				if staged_entry="$(git -C "$checkout" ls-files -s -- "$rel" 2>/dev/null)"; then
					staged_mode="$(printf '%s\n' "$staged_entry" |
						awk -v p="$rel" '$3 == "0" && $4 == p { print $1; exit }')"

openRepoTools:2165

  • [ -x "$checkout/$rel" ] tests whether the current user can execute the file, not the owner-execute bit Git uses when deciding whether a regular file is mode 100755. For example, a readable file owned by another account with mode 0744 makes this test false for the current user, while git add still records 100755, so step 8 can publish a mode this command did not write; group-executable files cause the opposite false refusal. Inspect the permission bits with a portable mode check instead (the existing mode_is helper uses find for this repository's GNU/BSD portability).
				if [ -x "$checkout/$rel" ] &&
					[ "$(git -C "$checkout" config --bool --get core.fileMode 2>/dev/null || :)" != "false" ]
  • Files reviewed: 2/2 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@brettheap
brettheap merged commit 957a26f into main Sep 16, 2026
7 checks passed
brettheap added a commit that referenced this pull request Sep 16, 2026
…e textual conflict in README.md, resolved as a union

`main` moved from f9e63f4 to 957a26f — #102 (every `chmod` `--install` performs
fails through `die`, and a second writer of either hook refuses whether or not
our own entry is beside it) and #101 (`wip init` stops reading a failed `git
status` as clean, refuses a template path whose ancestor is a symlink or not a
directory, refuses one staged at a mode it never wrote, and names a
skip-worktree path HEAD carries and the disk does not). Neither touches
`lanes-edit.sh`, so the guard and Amendment 16 sections merge untouched.

ONE TEXTUAL CONFLICT, IN README.md, AND IT IS A UNION. Both sides edited the
same sentence in the settings-merge paragraph: this branch's Amendment 16
raised twelve files to THIRTEEN (`lane-rename` joins `INSTALLABLES`), and #102
appended the new paragraph on a second writer refusing whether or not our own
entry sits beside it. Kept: "thirteen" (this branch's count — `openRepoTools`
itself already says thirteen throughout, unconflicted, since that count comes
from `INSTALLABLES` and not from this paragraph) followed by #102's whole
"A SECOND WRITER REFUSES..." paragraph, in main's order. `openRepoTools`,
`tests/test_install_skill_and_hook.py`, `tests/test_openrepotools_command.py`
and `tests/test_wip_init_command.py` merged with no conflict.

`bash tests/test_lane_helpers.sh` run to completion after this merge; see the
finishing-writer report for the count.

Lane: openrepotools-3 (openRepoTools-3)

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01EaHzfTLW4u9ukpWuw8Dt6r
brettheap added a commit that referenced this pull request Sep 16, 2026
… beside the supervised restart

`main` moved twice under this branch: every `chmod` `--install` performs now
fails through `die` and a second writer of either hook refuses whether or not
our own entry is beside it (#102), and `wip init` stops reading a failed
`git status` as clean, refuses a template path whose ancestor is a symlink or
not a directory, refuses one staged at a mode it never wrote, and names a
skip-worktree path HEAD carries and the disk does not (#101).

Both touch `openRepoTools`, `README.md` and three pytest files; this branch
touches none of them. The merge is a union with no overlapping hunk, which is
what `git merge` reports and what the file list proves: the shell suite's
`ort_text` assertions read `openRepoTools` from the tree and are unchanged on
either side.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EaHzfTLW4u9ukpWuw8Dt6r
brettheap added a commit that referenced this pull request Sep 16, 2026
…ide Amendment 18's binding reads — no file in either half is touched by the other

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01EaHzfTLW4u9ukpWuw8Dt6r
@brettheap
brettheap deleted the fix/wip-init-step7-ancestors-modes-sparse-and-status-failure branch October 3, 2026 18:49
brettheap added a commit that referenced this pull request Oct 4, 2026
Bring #97 onto a current base before the seam rework Brett Heap ruled on
2026-10-04 ("managed ledger owns enrolled lanes; #97 owns legacy — rework
both"). Main moved 14 commits past 957a26f, to daed209: #81 lane-rename,
#83 Amendment 18, #93 Amendment 19, #61 claim --force takeover, #146,
#119, #101-#103, #129, #131, #133, #135, #136, #139 and #134.

Four files conflicted, and in every one both intents survive:

- lanes-edit.sh, the function sections: both sides appended after
  migrate_state_cells. Main's Amendment 19(c)/(d) sweep and archive stay
  directly under it, because its header says "the shape
  `migrate-state-cells` has one screen up"; #97's lifecycle and
  inventory section follows them.
- lanes-edit.sh, the unknown-subcommand refusal: the union of both lists,
  56 names, the same set as the dispatcher's 56 arms.
- lanes-edit.sh, the exit-code table, and the manual's copy of it: #97's
  7 row ("another act got there first", in three verbs) is kept, and exit
  9 now has two meanings, one per verb. #61 spent 9 on `claim --force`'s
  abandoned takeover and #97 spent it on `lane-state`'s unreadable
  snapshot, and each PR took it as unused. Neither verb can return the
  other's 9, so the table names both and nothing is renumbered in a
  merge. The manual's 9 row said "(`claim` only)", which the merge would
  have made false; its 7 row now names #97's two fenced writers too, as
  the code table already did. The next commit moves #97's 9 to 10.
- lane-handoff, the late-record restart line: #129's
  `$lane_profile_word` (lclaude) with #97's lifecycle line under it.
- docs/README-lanes.md: Amendment 19's section, then #97's #91 section,
  so the amendment sections stay in number order.
- tests/test_lane_helpers.sh: main's Amendment 19 and Amendment 18
  sections run first, in main's order (A18's restores its fixtures), and
  #97's self-contained #91 section follows them, before the
  workstation-seam section, as it did on #97's branch.

lane-start auto-merged around #134's rewrite. #97's section 4a still
prints the reconciliation after Amendment 18's binding gate and before
section 5 and the STARTED/RESUMED write in 5b. AGENTS.md, README.md,
tests/test_repo_hygiene.py and skills/ are byte-identical to main, so
the 316- and 486-line caps already match the merged counts.

Locally, tests/run.sh -k 'lane_helpers_suite or repo_hygiene or
lane_start_claude_current or guard_launch_mode or install_skill_and_hook':
274 passed, 600 deselected, in 1560 s.

Lane: openRepoTools-3
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants