feat(git-extension): add configurable Conventional Commit support (#3390)
Summary
Implements issue #3390: adds a configurable commit_style option (fixed | conventional) to the bundled git extension's auto-commit feature.
commit_style: fixed(default) — unchanged, static configured messages.commit_style: conventional— thespeckit.git.commithook now instructs the agent to generate a Conventional Commit message from the diff and pass it explicitly toauto-commit.sh/auto-commit.ps1as a second argument.- If
commit_style: conventionalis set but no generated message is supplied, the scripts fail loudly (stderr message + exit 1) instead of silently committing with the fixed message — while still short-circuiting cleanly when there are no changes to commit.
Changes
extensions/git/config-template.yml,extensions/git/git-config.yml: newcommit_styleoption with docs.extensions/git/scripts/bash/auto-commit.sh: optional[generated_message]arg,commit_styleparsing, conventional-mode enforcement (ordered after the "no changes" check).extensions/git/scripts/powershell/auto-commit.ps1: mirrored PowerShell implementation.extensions/git/commands/speckit.git.commit.md: documents the new "Commit Message Styles" section and updated execution/config/graceful-degradation guidance.extensions/git/README.md: documents the new option in the configuration example.tests/extensions/git/test_git_extension.py: newTestAutoCommitBashCommitStyle/TestAutoCommitPowerShellCommitStyleregression tests covering fixed-default, conventional success, conventional missing-message failure, and no-changes short-circuit.
Testing
pytest tests/extensions/git/test_git_extension.py -v— all bash/PowerShell tests requiring bash/pwsh skip consistently in this environment (matching existingTestAutoCommitBash/TestAutoCommitPowerShellbehavior via@requires_bash/HAS_PWSH).- Manually validated all four scenarios (fixed default, conventional success, conventional missing-message failure, no-changes short-circuit) end-to-end against
auto-commit.ps1using Windows PowerShell, since pwsh (PowerShell 7) isn't installed in this environment. pytest tests/(full suite): 3614 passed, 295 skipped, 39 failed — all 39 failures are pre-existing, environment-specific (Windows symlink-permission tests and pwsh-only tests), unrelated to this change.ruff check extensions/git tests/extensions/git: all checks passed.
Fixes #3390
This PR was prepared with the assistance of GitHub Copilot (model: claude-sonnet-5, operating autonomously) on behalf of @dhruv-15-03.
/lgtm
Fixed the flaky macOS CI failure in pytest (macos-latest, 3.13): test_conventional_without_generated_message_fails asserted on result.stderr only, but pwsh's Write-Warning stream placement (stdout vs. stderr) isn't deterministic across platforms/pwsh versions. Updated the assertion to check the combined stdout+stderr, matching the pattern already used elsewhere in this file (e.g. test_not_a_repo_still_detected_with_autocrlf). Pushed as 7a6951c.
Please address Copilot feedback
@dhruv-15-03 could you follow up soon? Speckit is a moving target. Thx.
Addressed the outstanding Copilot review feedback in c1d245d:
- bash (
extensions/git/scripts/bash/auto-commit.sh): fixedcommit_styleparsing to correctly strip trailing YAML inline comments (e.g.commit_style: conventional # team standard). The previous regex only matched a single space before#, so quoted values with two+ spaces before the comment (e.g.commit_style: "conventional" # x) left a stray trailing"after quote-stripping. Now uses a{1,}interval to consume all whitespace + the comment together. - powershell: already handled this correctly (
\s+#.*$+.Trim()), verified with manual regex tests - no change needed. - tests: added regression coverage for
commit_stylevalues with trailing inline comments (bash + pwsh), plus the pwsh no-changes short-circuit regression test suggested in the review.
All existing + new tests pass locally (ruff clean, targeted commit_style test classes green).
Addressed the remaining Copilot review feedback in 5f20fd5:
- Validated
commit_styleagainst the documentedfixed/conventionalvalues in both bash and pwsh; an unrecognized value (e.g. a typo likeconventonal) now emits a warning and falls back tofixedinstead of silently mis-parsing. - Reworded the conventional-mode-without-generated-message message from "skipped auto-commit" to "aborting auto-commit" (the script exits 1, which is a failure, not a skip), and added the concrete remediation (pass the generated message as arg 2, or set
commit_style: fixed). - Added bash + pwsh regression tests covering the unknown
commit_stylefallback.
Left the test-duplication suggestion (parametrizing the bash/pwsh commit-style test classes) unaddressed for now since it's a structural refactor rather than a behavior bug; happy to do it in a follow-up if preferred.
All changes verified locally (bash syntax check, PowerShell AST parse, manual script runs for both the unknown-style-fallback and abort-message paths).
Please address Copilot feedback
Addressed the latest Copilot review feedback in 70024d4: the bash commit_style parser now uses grep -m1 to limit matching to the first commit_style: line in the config, preventing value concatenation if a config accidentally contains duplicate keys (e.g. from a bad merge). Added a regression test (test_duplicate_commit_style_lines_use_first_match) covering this case. The PowerShell version already limited to the first match via its break statement, so no change was needed there.
Please address Copilot feedback
- Whitespace bug: removed
tr -d '[:space:]'from the bashcommit_styleparsing pipeline. It was stripping all whitespace from the value (not just surrounding it), socommit_style: con ventionalwas silently normalized toconventionalinstead of being rejected as unknown - inconsistent with the PowerShell version, which already rejected it correctly. Both now behave the same. - Command injection risk: added a file-based message channel -
--message-file <path>(bash) /-MessageFile <path>(PowerShell) - so an agent-generated commit message (which may contain quotes,$(...), or backticks) is read from a file instead of being interpolated into a shell command string. Updatedspeckit.git.commit.mdto instruct writing the message to a temp file via the file-editing tool and passing the path, explicitly warning against shell inlining. The old positional-argument form is kept for backward compatibility. - Test coverage: added explicit
commit_style: fixedtests (previously only the absent-key default was covered), plus success/missing-file tests for the new message-file flag, including an injection-shaped message (feat: add $(dangerous)injectiontest) verified to land in the commit message verbatim with no shell expansion - for both bash and PowerShell suites.
All three fixes were manually smoke-tested locally (bash and PowerShell) confirming correct behavior before pushing.
Please address Copilot feedback
Addressed the latest Copilot review feedback in e16db03: the message file passed via --message-file/-MessageFile was read but left in the worktree. If written inside the project (e.g. by an agent's file-editing tool), it was staged into the commit by git add ., and its mere presence as an untracked file could also defeat the no-changes short-circuit, producing a spurious commit containing only that file. Both scripts now remove the transport file immediately after its content is captured, before the change-detection check and before staging. Added bash + pwsh regression tests covering: (1) the message file is excluded from the resulting commit and removed from disk, and (2) when it is the only 'change' present, auto-commit correctly reports no changes rather than committing.
Verified locally (bash syntax check, PowerShell AST parse, and manual runs of both new scenarios against the real test fixtures).
Thank you!