Skip to content

Commit 5f20fd5

Browse files
dhruv-15-03Copilot
andcommitted
fix(git-extension): validate commit_style and reword abort message per review
Address Copilot review feedback on PR #3413: - Validate commit_style against the documented fixed/conventional values; an unrecognized value now warns and falls back to fixed instead of silently mis-parsing. - Reword the conventional-mode-without-generated-message message from 'skipped auto-commit' to 'aborting auto-commit' since the script exits 1 (a failure, not a skip), and include the actionable remediation. - Add regression tests (bash + pwsh) covering the unknown commit_style fallback. Assisted-by: GitHub Copilot (model: claude-sonnet-5, autonomous) Co-authored-by: Copilot App <[email protected]>
1 parent c1d245d commit 5f20fd5

3 files changed

Lines changed: 65 additions & 4 deletions

File tree

β€Žextensions/git/scripts/bash/auto-commit.shβ€Ž

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,16 @@ _commit_style="fixed"
5656
if [ -f "$_config_file" ]; then
5757
# Top-level scalar key: commit_style (fixed | conventional)
5858
_style_val=$(grep '^commit_style:' "$_config_file" 2>/dev/null | sed 's/^commit_style:[[:space:]]*//' | sed 's/[[:space:]]\{1,\}#.*$//' | sed 's/[[:space:]]*$//' | sed 's/^["'\'']//' | sed 's/["'\'']*$//' | tr -d '[:space:]' | tr '[:upper:]' '[:lower:]')
59-
[ -n "$_style_val" ] && _commit_style="$_style_val"
59+
if [ -n "$_style_val" ]; then
60+
case "$_style_val" in
61+
fixed|conventional)
62+
_commit_style="$_style_val"
63+
;;
64+
*)
65+
echo "[specify] Warning: unknown commit_style '$_style_val' in git-config.yml (expected 'fixed' or 'conventional'); defaulting to 'fixed'" >&2
66+
;;
67+
esac
68+
fi
6069

6170
# Parse the auto_commit section for this event.
6271
# Look for auto_commit.<event_name>.enabled and .message
@@ -139,7 +148,7 @@ if [ "$_commit_style" = "conventional" ]; then
139148
if [ -n "$GENERATED_MESSAGE" ]; then
140149
_commit_msg="$GENERATED_MESSAGE"
141150
else
142-
echo "[specify] Error: commit_style is 'conventional' but no generated commit message was supplied; skipped auto-commit" >&2
151+
echo "[specify] Error: commit_style is 'conventional' but no generated commit message was supplied; aborting auto-commit (pass the generated message as arg 2, or set commit_style: fixed)" >&2
143152
exit 1
144153
fi
145154
fi

β€Žextensions/git/scripts/powershell/auto-commit.ps1β€Ž

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ if (Test-Path $configFile) {
6767
foreach ($line in Get-Content $configFile) {
6868
if ($line -match '^commit_style:\s*(.+)$') {
6969
$styleVal = (($matches[1] -replace '\s+#.*$', '').Trim()) -replace '^["'']' -replace '["'']$'
70-
if ($styleVal) { $commitStyle = $styleVal.ToLower() }
70+
if ($styleVal) {
71+
$styleVal = $styleVal.ToLower()
72+
if ($styleVal -eq 'fixed' -or $styleVal -eq 'conventional') {
73+
$commitStyle = $styleVal
74+
} else {
75+
Write-Warning "[specify] Warning: unknown commit_style '$styleVal' in git-config.yml (expected 'fixed' or 'conventional'); defaulting to 'fixed'"
76+
}
77+
}
7178
break
7279
}
7380
}
@@ -161,7 +168,7 @@ if ($commitStyle -eq 'conventional') {
161168
if ($GeneratedMessage) {
162169
$commitMsg = $GeneratedMessage
163170
} else {
164-
Write-Warning "[specify] Error: commit_style is 'conventional' but no generated commit message was supplied; skipped auto-commit"
171+
Write-Warning "[specify] Error: commit_style is 'conventional' but no generated commit message was supplied; aborting auto-commit (pass the generated message as arg 2, or set commit_style: fixed)"
165172
exit 1
166173
}
167174
}

β€Žtests/extensions/git/test_git_extension.pyβ€Ž

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,28 @@ def test_conventional_with_trailing_inline_comment(self, tmp_path: Path):
12001200
assert "feat: add OAuth specification" in log.stdout
12011201
assert "[Spec Kit] Add specification" not in log.stdout
12021202

1203+
def test_unknown_commit_style_defaults_to_fixed(self, tmp_path: Path):
1204+
"""An unrecognized commit_style value falls back to 'fixed' with a warning,
1205+
instead of silently mis-parsing or crashing."""
1206+
project = _setup_project(tmp_path)
1207+
_write_config(project, (
1208+
"commit_style: conventonal\n"
1209+
"auto_commit:\n"
1210+
" default: false\n"
1211+
" after_specify:\n"
1212+
" enabled: true\n"
1213+
' message: "[Spec Kit] Add specification"\n'
1214+
))
1215+
(project / "new-file.txt").write_text("content")
1216+
result = _run_bash("auto-commit.sh", project, "after_specify")
1217+
assert result.returncode == 0
1218+
assert "unknown commit_style" in result.stderr.lower()
1219+
log = subprocess.run(
1220+
["git", "log", "--oneline", "-1"],
1221+
cwd=project, capture_output=True, text=True,
1222+
)
1223+
assert "[Spec Kit] Add specification" in log.stdout
1224+
12031225

12041226
@pytest.mark.skipif(not HAS_PWSH, reason="pwsh not available")
12051227
class TestAutoCommitPowerShell:
@@ -1374,6 +1396,29 @@ def test_conventional_with_trailing_inline_comment(self, tmp_path: Path):
13741396
assert "feat: add OAuth specification" in log.stdout
13751397
assert "[Spec Kit] Add specification" not in log.stdout
13761398

1399+
def test_unknown_commit_style_defaults_to_fixed(self, tmp_path: Path):
1400+
"""An unrecognized commit_style value falls back to 'fixed' with a warning,
1401+
instead of silently mis-parsing or crashing."""
1402+
project = _setup_project(tmp_path)
1403+
_write_config(project, (
1404+
"commit_style: conventonal\n"
1405+
"auto_commit:\n"
1406+
" default: false\n"
1407+
" after_specify:\n"
1408+
" enabled: true\n"
1409+
' message: "[Spec Kit] Add specification"\n'
1410+
))
1411+
(project / "new-file.txt").write_text("content")
1412+
result = _run_pwsh("auto-commit.ps1", project, "after_specify")
1413+
assert result.returncode == 0
1414+
combined = (result.stdout or "") + (result.stderr or "")
1415+
assert "unknown commit_style" in combined.lower()
1416+
log = subprocess.run(
1417+
["git", "log", "--oneline", "-1"],
1418+
cwd=project, capture_output=True, text=True,
1419+
)
1420+
assert "[Spec Kit] Add specification" in log.stdout
1421+
13771422

13781423
# ── auto-commit.ps1 CRLF warning tests (issue #2253) ────────────────────────
13791424

0 commit comments

Comments
Β (0)