Skip to content

Every git the library runs takes a context: a hanging git can be stopped, and a stopped run says so - #86

Merged
closer-claudio merged 1 commit into
mainfrom
claudio/20261115-contexts
Nov 15, 2026
Merged

closer-claudio merged 1 commit into
mainfrom
claudio/20261115-contexts

Conversation

@closer-claudio

Copy link
Copy Markdown

🎯 Why

Every git subprocess the library runs was started with exec.Command: nothing could stop one. A program using the library on a range it was handed had no way out of a git that hangs, and the command's own shutdown context went nowhere.

For #37 (its noctx findings).

🛠️ What

The breaking change, for a caller of the two packages: a context comes first in git.Commits, Check, Show, LogUntil, LogCommit, FetchHeadCommit and HeadCommit, in validate.NewRunner, Runner.Run and validate.Commit, and in a rule's Run (a rule may run git itself; dangling-whitespace does).

  • git is started with exec.CommandContext, which kills it when the context ends. A killed git reports "signal: killed", not why, so when the context is done the error is the context's, with git's own after it. A range check that was stopped says so, and not that the range does not resolve.
  • Runner.Run stops among the commits too: it looks at the context before each commit and after it, and returns the context's error. Results holds the commits validated whole, and nothing of the one a rule was stopped at. Without that, a run stopped at its first commit returned nil with every later commit recorded as failing validation.
  • The command passes the context its shutdown gives it, so an interrupt stops the run.
  • .lint-go.yaml: noctx leaves the backlog for git/commits.go.

🧪 How

  1. A context reaches every git the library runs
    • V: just lint and just test pass on macOS arm64 (62 tests).
    • V: a stand-in git that never ends (the test binary, run as git) is killed when the context is cancelled while it runs, and the call returns context.Canceled together with git's end by a kill; under a done context no git is started and each of the seven functions returns the context's error.
    • V: Run hands its context to every rule; under a done one it lists nothing and runs no rule; a context that ends in a rule or between two commits stops the run there, with the earlier commits' results and no other (TestRunStopsAmongTheCommits, three rows over five commits).
    • V: broken on purpose, each alone: git not run under the context; a killed git keeping its own error; the context's error replacing git's; Run, Commit or NewRunner handing on another context; the check before a commit removed; the check after a commit removed. Each fails.
    • U: Linux and Windows, left to CI.

📝 Notes

  • Nothing is tagged between this and the Runner's earlier change of signature, so a caller meets both at once.

Every `git` subprocess was started with `exec.Command`: nothing could
stop one. A program using the library on a range it was handed had no
way out of a `git` that hangs, and the command's own shutdown context
went nowhere.

The context is threaded through: `git.Commits`, `Check`, `Show`,
`LogUntil`, `LogCommit`, `FetchHeadCommit` and `HeadCommit` take it
first, as do `validate.NewRunner`, `Runner.Run`, `validate.Commit` and
a rule's `Run`, since a rule may run git itself (dangling-whitespace
does). The command passes the context its shutdown gives it.

git is started with `exec.CommandContext`, which kills it when the
context ends. A killed git reports "signal: killed", not why, so every
run of git goes through `ended`: when the context is done, the error is
the context's, with git's own after it. A range check that was stopped
says so, and not that the range does not resolve.

`Run` stops among the commits too. It looks at the context before each
commit and after it, and returns the context's error: `Results` holds
the commits validated whole, and nothing of the one a rule was stopped
at, whose rules return the stop and not a judgment. Without that, a run
stopped at its first commit returned nil with every later commit
recorded as failing validation.

This breaks every caller of the two packages, as the Runner's change
before it did; nothing is tagged between them.

Tests: a stand-in git that never ends (the test binary, run as git) is
killed when the context is cancelled while it runs, the call returning
`context.Canceled` together with git's end by a kill; under a done
context no git is started and each of the seven functions returns the
context's error; `Run` hands its context to every rule and, under a
done one, lists nothing and runs no rule; a context that ends in a rule
or between two commits stops the run there, with the earlier commits'
results and no other; `NewRunner` stops looking for
a commit when its context ends while git runs. Broken on purpose, each
alone: git not run under the context; a killed git keeping its own
error; the context's error replacing git's; `Run`, `Commit` or
`NewRunner` handing on another context: each fails.

noctx leaves the lint backlog for git/commits.go, and the five debug
logs that now have a context use it.

For #37.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: closer-claudio <claudio@farcloser.world>
@closer-claudio closer-claudio added the breaking Breaks a consumer label Nov 15, 2026
@closer-claudio

Copy link
Copy Markdown
Author

Reviewed at 2a06c0d

@closer-claudio
closer-claudio merged commit d894685 into main Nov 15, 2026
14 checks passed
@closer-claudio
closer-claudio deleted the claudio/20261115-contexts branch November 15, 2026 22:45
closer-claudio added a commit that referenced this pull request Nov 16, 2026
The table of what upstream does not have stops at the shallow-clone
refusal. Three later changes a user of the command can see have no
row: QUIET in the environment no longer quiets it
(#81), errors say
what was being done
(#83), and a run can
be stopped (#86).

Upstream's main is still the commit forked from: the comparison of
a8d4555 with main, asked of GitHub today, is zero commits ahead. The
"Reviewed through" line takes today's date.

For #50.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: closer-claudio <claudio@farcloser.world>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaks a consumer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants