Repository navigation
fix(scripts): let smart-commit.sh take a message, body and trailers - #464
Merged
Merged
Conversation
core.adf requires commits via scripts/smart-commit.sh, but the script took only --dry-run and --merge and generated every subject itself (any package change became "feat(<scope>): apply logical updates"), with no body or trailers. Agents could not follow the rule, so every commit bypassed it. Add -m (repeatable, one paragraph each), -F <file> and --trailer 'Key: value' (placed by git interpret-trailers). With a message, all substantive changes go into one commit; without one, the grouped default is unchanged. --merge and --dry-run honor the message. Bad input exits 2 before anything is staged. The pre-commit hook still runs on every path. Tests run the real script in a throwaway repo (Git's bash on Windows, since plain bash can be WSL). Closes: #459 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each case spawns bash and several git processes; under load on Windows they exceeded vitest's 5s default. Use 60s for the tests and the setup hook, matching the repo's other process-spawning tests. Refs: #459 Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Set core.hooksPath and check the hook before every path, --merge included; before, --merge could commit without the hook. - Pass --no-divider to git interpret-trailers so a '---' line in the body is not read as a patch divider. - Reject multi-line --trailer values (one flag could forge a second trailer); allow 'Key:value' like git. - -F - reads the message from stdin. - Never commit a -F message file that lives inside the repo. - If a commit fails (e.g. the hook), unstage its files so the script can be rerun. - List paths with core.quotePath=false so non-ASCII files are committed, not skipped. - No 'feat: commit created' warning under --dry-run. Tests cover each case, including --merge with an unset hooksPath and a failing hook; the new cases fail against the previous script. Refs: #459 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Round-2 review of #464: - Find an in-repo message file with git rev-parse (--show-toplevel and --show-prefix) instead of comparing pwd strings, whose spelling can differ from git's top level on Windows (Temp paths, case), which let the file leak into the commit. - Run interpret-trailers with an unused core.commentChar so body lines such as '#459 caused this' are not treated as comments and the trailers stay after the body. - A failing hook on the grouped path now says that earlier group commits were kept. - Tests: '#' body lines, 'Refs:#1', -F relative to a subdirectory, a differently spelled cwd (Windows), a pre-staged index, a failing hook on the grouped path, no --dry-run feat warning. Refs: #459 Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
core.adf(load-bearing) says commits go throughscripts/smart-commit.shonly. But the script accepted only--dry-runand--merge, and it generated every subject itself: any package change becamefeat(<scope>): apply logical updates, with no body or trailers. No agent or maintainer could follow the rule, so every commit bypassed it. This PR makes the rule followable without changing it.New options (
scripts/smart-commit.sh --help)-m <message>, repeatable. Each one becomes a paragraph, as withgit commit -m.-F <file>takes the whole message (subject, body and trailers) from a file;-F -reads it from stdin. A message file inside the repo (located withgit rev-parse, so path spelling doesn't matter) is never committed, except on--merge, wheregit add -uwould still include a tracked message file you modified.--trailer 'Key: value', repeatable and single-line. Trailers are placed bygit interpret-trailers --no-divider: appended to an existing trailer block, or added as a new paragraph, a---line in the body stays body text, and body lines starting with#(such as#459 caused this) are not treated as comments.Behaviour
--dry-runprints the message and the files, and commits nothing.--mergeuses the message instead of--no-edit.-mtogether with-F, a trailer with no message, an empty message, a malformed trailer, a missing file, and an unknown argument.core.hooksPath .githooksand checks the hook exists before any commit path, including--merge, which onmaincould commit without the hook. It never passes--no-verify.core.quotePath=false, so non-ASCII file names are committed rather than skipped as "whitespace-only".Not changed: the rule in
.ai/core.adf. Whether to relax it ("Conventional Commits; the script is available") is the owner's governance call, so this PR leaves it as is.Verification (local; GitHub Actions isn't running in this repo right now)
-m, a body and--trailer(seegit log). The hook ran each time (tsc plusadf evidence: PASS).packages/cli/src/__tests__/smart-commit-script.test.ts(26 cases) runs the real script in a throwaway git repo. Of the cases added after each review, those targeting a fixed bug fail against the previous script (9 after round 1; 3 after round 2). The rest are regression coverage for behaviour that already worked.-Fwith trailers merged into the file's trailer block;-F -; a---body line; an in-repo message file not committed; non-ASCII, space-named, deleted and renamed files; a failing hook blocking the commit, unstaging and allowing a rerun;--mergerunning the hook withcore.hooksPathunset and a failing hook blocking the merge;--dry-runwith no commit and a clean index; the grouped default unchanged;#body lines;Refs:#1;-Frelative to a subdirectory and from a differently spelled cwd (Windows); a pre-staged index; a failing hook on the grouped path; no--dry-runfeat warning; and 8 rejection cases (exit 2, no commit), including a multi-line trailer.bashcan resolve to WSL. It skips if no bash 4+ is found.pnpm exec tsc --build tsconfig.build.json,pnpm exec tsc --noEmit -p tsconfig.json, andadf evidence --auto-measure --ciall pass.adf-vendor-doctor-score. A clean full run is still to come, on a quiet machine.Closes #459
Part of #437
🤖 Generated with Claude Code