spec-kit icon indicating copy to clipboard operation
spec-kit copied to clipboard

feat(git-extension): add configurable Conventional Commit support (#3390)

Open dhruv-15-03 opened this issue 4 months ago • 5 comments

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 — the speckit.git.commit hook now instructs the agent to generate a Conventional Commit message from the diff and pass it explicitly to auto-commit.sh / auto-commit.ps1 as a second argument.
  • If commit_style: conventional is 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: new commit_style option with docs.
  • extensions/git/scripts/bash/auto-commit.sh: optional [generated_message] arg, commit_style parsing, 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: new TestAutoCommitBashCommitStyle / TestAutoCommitPowerShellCommitStyle regression 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 existing TestAutoCommitBash/TestAutoCommitPowerShell behavior 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.ps1 using 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.

dhruv-15-03 avatar Jul 08 '26 16:07 dhruv-15-03

/lgtm

grafvonb avatar Jul 09 '26 06:07 grafvonb

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.

dhruv-15-03 avatar Jul 10 '26 07:07 dhruv-15-03

Please address Copilot feedback

mnriem avatar Jul 10 '26 20:07 mnriem

@dhruv-15-03 could you follow up soon? Speckit is a moving target. Thx.

grafvonb avatar Jul 11 '26 04:07 grafvonb

Addressed the outstanding Copilot review feedback in c1d245d:

  • bash (extensions/git/scripts/bash/auto-commit.sh): fixed commit_style parsing 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_style values 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).

dhruv-15-03 avatar Jul 11 '26 11:07 dhruv-15-03

Addressed the remaining Copilot review feedback in 5f20fd5:

  • Validated commit_style against the documented fixed/conventional values in both bash and pwsh; an unrecognized value (e.g. a typo like conventonal) now emits a warning and falls back to fixed instead 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_style fallback.

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).

dhruv-15-03 avatar Jul 15 '26 16:07 dhruv-15-03

Please address Copilot feedback

mnriem avatar Jul 15 '26 17:07 mnriem

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.

dhruv-15-03 avatar Jul 18 '26 17:07 dhruv-15-03

Please address Copilot feedback

mnriem avatar Jul 21 '26 13:07 mnriem

  • Whitespace bug: removed tr -d '[:space:]' from the bash commit_style parsing pipeline. It was stripping all whitespace from the value (not just surrounding it), so commit_style: con ventional was silently normalized to conventional instead 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. Updated speckit.git.commit.md to 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: fixed tests (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) injection test) 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.

dhruv-15-03 avatar Jul 22 '26 17:07 dhruv-15-03

Please address Copilot feedback

mnriem avatar Jul 22 '26 17:07 mnriem

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).

dhruv-15-03 avatar Jul 23 '26 15:07 dhruv-15-03

Thank you!

mnriem avatar Jul 23 '26 15:07 mnriem