Skip to content

Only refuse partial ready --fix files that formatting changes#17

Merged
cgraf78 merged 2 commits into
mainfrom
fix-ready-partial-format-check
Jul 2, 2026
Merged

Only refuse partial ready --fix files that formatting changes#17
cgraf78 merged 2 commits into
mainfrom
fix-ready-partial-format-check

Conversation

@cgraf78

@cgraf78 cgraf78 commented Jul 2, 2026

Copy link
Copy Markdown
Owner

Summary

Stop sley ready --fix --commit from blocking commits of partially
staged files whose staged content is already formatter-clean.

The commit gate refused every partially staged file (both staged and
unstaged hunks) upfront, to avoid folding formatter output across the
unstaged hunk. But that also blocked the common "stage some hunks, keep
editing, then commit" workflow even when nothing needed formatting — a
regression the dotfiles githook-test guards against ("partial-stage
clean content: commit succeeds").

Decide per file by result instead of refusing upfront:

  • Pass 1 probes partially staged files without mutating them: back the
    worktree copy up, format, then always restore it. If formatting would
    have changed the file, record it; a clean partial file is a pure no-op.
    If the backup can't be made, refuse rather than risk an unrecoverable
    clobber.
  • If any partial file would be reformatted, refuse before touching the
    rest of the batch, so a refusal never leaves other files reformatted in
    the worktree.
  • Pass 2 formats every non-partial file in place as before, reporting the
    re-stage requirement when the formatter changes a fully staged file.

The standalone sley fix command still refuses partial files outright;
the commit gate is deliberately more permissive so clean partial-stage
commits succeed.

Testing

  • update the ready --fix --commit partial-staging tests: a partial file
    that the formatter WOULD change is still refused (exit 2) with the
    worktree left intact (the probe reverts); a mixed batch refuses before
    the fully staged file is ever formatted
  • add a regression test mirroring the commit hook: a clean partial-staged
    file with a no-op formatter is NOT refused, the worktree is left intact,
    and the run reaches exit 0
  • verified the dotfiles githook-test passes against this build
    (PATH=<worktree>/bin → 51 passed, 0 failed), including the two
    partial-stage assertions that fail on the previous behavior
  • full suite green (./test/sley-test: ok); checkrun lint and
    shellcheck -x lib/sley/ready.sh clean

cgraf78 added 2 commits July 1, 2026 23:59
Summary

Stop `sley ready --fix --commit` from blocking commits of partially
staged files whose staged content is already formatter-clean.

The commit gate refused every partially staged file (both staged and
unstaged hunks) upfront, to avoid folding formatter output across the
unstaged hunk. But that also blocked the common "stage some hunks, keep
editing, then commit" workflow even when nothing needed formatting — a
regression the dotfiles `githook-test` guards against ("partial-stage
clean content: commit succeeds").

Decide per file by result instead of refusing upfront:

- Pass 1 probes partially staged files without mutating them: back the
  worktree copy up, format, then always restore it. If formatting would
  have changed the file, record it; a clean partial file is a pure no-op.
  If the backup can't be made, refuse rather than risk an unrecoverable
  clobber.
- If any partial file would be reformatted, refuse before touching the
  rest of the batch, so a refusal never leaves other files reformatted in
  the worktree.
- Pass 2 formats every non-partial file in place as before, reporting the
  re-stage requirement when the formatter changes a fully staged file.

The standalone `sley fix` command still refuses partial files outright;
the commit gate is deliberately more permissive so clean partial-stage
commits succeed.

Testing

- update the `ready --fix --commit` partial-staging tests: a partial file
  that the formatter WOULD change is still refused (exit 2) with the
  worktree left intact (the probe reverts); a mixed batch refuses before
  the fully staged file is ever formatted
- add a regression test mirroring the commit hook: a clean partial-staged
  file with a no-op formatter is NOT refused, the worktree is left intact,
  and the run reaches exit 0
- verified the dotfiles `githook-test` passes against this build
  (`PATH=<worktree>/bin` → 51 passed, 0 failed), including the two
  partial-stage assertions that fail on the previous behavior
- full suite green (`./test/sley-test`: ok); `checkrun lint` and
  `shellcheck -x lib/sley/ready.sh` clean
Summary

Address two review findings on the partial-staged probe.

- the restore `cp -p` return code was unchecked: if the restore failed
  after the formatter had already rewritten the worktree file (disk full,
  file turned read-only), execution fell through and deleted the only
  backup — the exact clobber this guard prevents. Now check the restore,
  and on failure keep the backup and refuse loudly, naming both paths.
- redirect the formatter's stdin from /dev/null in both passes so a
  formatter that reads stdin can't drain the herestring driving the loop,
  matching the standalone `_sley_fix` guard.

Testing

- full suite green (`./test/sley-test`: ok); `checkrun lint` and
  `shellcheck -x lib/sley/ready.sh` clean
- dotfiles `githook-test` still passes against this build (51/0)
@cgraf78 cgraf78 merged commit 33baec6 into main Jul 2, 2026
6 checks passed
@cgraf78 cgraf78 deleted the fix-ready-partial-format-check branch July 2, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant