Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion extensions/catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"git": {
"name": "Git Branching Workflow",
"id": "git",
"version": "1.0.9",
"version": "1.0.10",
"description": "Feature branch creation, numbering (sequential/timestamp), validation, and Git remote detection",
"author": "spec-kit-core",
"repository": "https://github.com/github/spec-kit",
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ schema_version: "1.0"
extension:
id: git
name: "Git Branching Workflow"
version: "1.0.9"
version: "1.0.10"
description: "Feature branch creation, numbering (sequential/timestamp), templating, validation, and Git remote detection"
author: spec-kit-core
repository: https://github.com/github/spec-kit
Expand Down
11 changes: 10 additions & 1 deletion extensions/git/scripts/powershell/auto-commit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,16 @@ $ErrorActionPreference = 'Continue'
try {
$out = git add . 2>&1 | Out-String
if ($LASTEXITCODE -ne 0) { throw "git add failed: $out" }
$out = git commit -q -m $commitMsg 2>&1 | Out-String
# Pass the message in a file: Windows PowerShell 5.1 does not escape
# double quotes in native arguments, so `-m` split a message such as
# 'add "remember me" option' into extra pathspecs.
$msgFile = [System.IO.Path]::GetTempFileName()
try {
[System.IO.File]::WriteAllText($msgFile, $commitMsg, (New-Object System.Text.UTF8Encoding($false)))
$out = git commit -q -F $msgFile 2>&1 | Out-String
} finally {
Remove-Item -LiteralPath $msgFile -Force -ErrorAction SilentlyContinue
}
if ($LASTEXITCODE -ne 0) { throw "git commit failed: $out" }
} catch {
Write-Warning "[specify] Error: $_"
Expand Down
11 changes: 10 additions & 1 deletion extensions/git/scripts/powershell/initialize-repo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ try {
if ($LASTEXITCODE -ne 0) { throw "git init failed: $out" }
$out = git add . 2>&1 | Out-String
if ($LASTEXITCODE -ne 0) { throw "git add failed: $out" }
$out = git commit --allow-empty -q -m $commitMsg 2>&1 | Out-String
# Pass the message in a file: Windows PowerShell 5.1 does not escape
# double quotes in native arguments, so `-m` split a message such as
# 'Initial "Spec Kit" setup' into extra pathspecs.
$msgFile = [System.IO.Path]::GetTempFileName()
try {
[System.IO.File]::WriteAllText($msgFile, $commitMsg, (New-Object System.Text.UTF8Encoding($false)))
$out = git commit --allow-empty -q -F $msgFile 2>&1 | Out-String
} finally {
Remove-Item -LiteralPath $msgFile -Force -ErrorAction SilentlyContinue
}
if ($LASTEXITCODE -ne 0) { throw "git commit failed: $out" }
} catch {
Write-Warning "[specify] Error: $_"
Expand Down
130 changes: 129 additions & 1 deletion tests/extensions/git/test_git_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def test_manifest_validates(self):

m = ExtensionManifest(EXT_DIR / "extension.yml")
assert m.id == "git"
assert m.version == "1.0.9"
assert m.version == "1.0.10"

def test_manifest_commands(self):
"""Manifest declares expected commands."""
Expand Down Expand Up @@ -2353,6 +2353,134 @@ def test_create_branch_reads_branch_prefix_as_utf8(self, tmp_path: Path, exe: st
]


# ── PowerShell commit messages with double quotes ────────────────────────────


@pytest.mark.parametrize(
"exe",
[
pytest.param(
"pwsh",
marks=pytest.mark.skipif(not HAS_PWSH, reason="pwsh not available"),
id="pwsh",
),
pytest.param(
WINDOWS_POWERSHELL,
marks=pytest.mark.skipif(
not WINDOWS_POWERSHELL, reason="Windows PowerShell 5.1 not available"
),
id="windows-powershell-5.1",
),
],
)
class TestPowerShellQuotedCommitMessages:
"""Commit messages with double quotes must reach git unchanged.

Windows PowerShell 5.1 does not escape embedded double quotes when it
builds a native command line, so `git commit -m 'add "remember me" option'`
arrived as extra arguments that git rejected as pathspecs, and a quoted
word with no space lost its quotes. PowerShell 7.3+ escapes them, so only
the windows-powershell-5.1 case can reproduce it.
"""

@staticmethod
def _subject(project: Path) -> str:
out = subprocess.run(
["git", "log", "-1", "--format=%s"], cwd=project, capture_output=True, check=True
)
return out.stdout.decode("utf-8").strip()

@staticmethod
def _temp_env(tmp_path: Path) -> tuple[Path, dict]:
"""Point the script's temp directory at an empty folder we can inspect."""
temp_dir = tmp_path / "temp"
temp_dir.mkdir()
return temp_dir, {"TEMP": str(temp_dir), "TMP": str(temp_dir), "TMPDIR": str(temp_dir)}

@pytest.mark.parametrize(
"message",
['feat: add "remember me" option', 'feat:"x"'],
ids=["quoted-words", "quotes-without-spaces"],
)
def test_auto_commit_message_file_keeps_double_quotes(
self, tmp_path: Path, exe: str, message: str
):
project = _setup_project(tmp_path / "project")
_write_config(project, (
"commit_style: conventional\n"
"auto_commit:\n"
" default: false\n"
" after_specify:\n"
" enabled: true\n"
))
(project / "new-file.txt").write_text("content")
msg_file = project / "commit-msg.txt"
msg_file.write_text(f"{message}\n", encoding="utf-8")
temp_dir, temp_env = self._temp_env(tmp_path)

result = _run_pwsh(
"auto-commit.ps1", project, "after_specify", "-MessageFile", str(msg_file),
env_extra=temp_env, exe=exe,
)

assert result.returncode == 0, result.stdout + result.stderr
assert self._subject(project) == message
assert list(temp_dir.iterdir()) == []

def test_auto_commit_configured_message_keeps_double_quotes(self, tmp_path: Path, exe: str):
project = _setup_project(tmp_path)
_write_config(project, (
"auto_commit:\n"
" default: false\n"
" after_specify:\n"
" enabled: true\n"
""" message: 'Add "remember me" spec'\n"""
))
(project / "new-file.txt").write_text("content")

result = _run_pwsh("auto-commit.ps1", project, "after_specify", exe=exe)

assert result.returncode == 0, result.stdout + result.stderr
assert self._subject(project) == 'Add "remember me" spec'

def test_initialize_repo_init_commit_message_keeps_double_quotes(
self, tmp_path: Path, exe: str
):
project = _setup_project(tmp_path, git=False)
_write_config(project, """init_commit_message: 'Initial "Spec Kit" setup'\n""")

result = _run_pwsh("initialize-repo.ps1", project, exe=exe)

assert result.returncode == 0, result.stdout + result.stderr
assert self._subject(project) == 'Initial "Spec Kit" setup'

def test_auto_commit_rejected_commit_fails_without_leaving_temp_files(
self, tmp_path: Path, exe: str
):
"""A commit that git refuses still fails the script and cleans up."""
project = _setup_project(tmp_path / "project")
_write_config(project, (
"auto_commit:\n"
" default: false\n"
" after_specify:\n"
" enabled: true\n"
))
hook = project / ".git" / "hooks" / "commit-msg"
hook.write_text("#!/bin/sh\necho 'rejected by hook' >&2\nexit 1\n", encoding="utf-8", newline="\n")
hook.chmod(0o755)
(project / "new-file.txt").write_text("content")
temp_dir, temp_env = self._temp_env(tmp_path)

result = _run_pwsh(
"auto-commit.ps1", project, "after_specify", env_extra=temp_env, exe=exe
)

assert result.returncode == 1, result.stdout + result.stderr
assert "git commit failed" in result.stdout + result.stderr
assert self._subject(project) == "seed"
assert list(temp_dir.iterdir()) == []


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


Expand Down
Loading