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.3",
"version": "1.0.4",
"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.3"
version: "1.0.4"
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
7 changes: 7 additions & 0 deletions extensions/git/scripts/powershell/initialize-repo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ try {
} catch { }

# Initialize
# Relax ErrorActionPreference so git warnings on stderr (e.g. CRLF notices)
# do not become terminating errors in Windows PowerShell 5.1; real failures
# are still caught through $LASTEXITCODE.
$savedEAP = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
try {
$out = git init -q 2>&1 | Out-String
if ($LASTEXITCODE -ne 0) { throw "git init failed: $out" }
Expand All @@ -64,6 +69,8 @@ try {
} catch {
Write-Warning "[specify] Error: $_"
exit 1
} finally {
$ErrorActionPreference = $savedEAP
}

Write-Host "[OK] Git repository initialized"
89 changes: 85 additions & 4 deletions tests/extensions/git/test_git_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import pytest

from tests.conftest import requires_bash
from tests.parity_helpers import WINDOWS_POWERSHELL

PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent.parent
EXT_DIR = PROJECT_ROOT / "extensions" / "git"
Expand Down Expand Up @@ -156,12 +157,18 @@ def _run_bash(script_name: str, cwd: Path, *args: str, env_extra: dict | None =
)


def _run_pwsh(script_name: str, cwd: Path, *args: str, env_extra: dict | None = None) -> subprocess.CompletedProcess:
"""Run an extension PowerShell script."""
def _run_pwsh(
script_name: str,
cwd: Path,
*args: str,
env_extra: dict | None = None,
exe: str = "pwsh",
) -> subprocess.CompletedProcess:
"""Run an extension PowerShell script (pwsh unless *exe* names another host)."""
script = cwd / ".specify" / "extensions" / "git" / "scripts" / "powershell" / script_name
env = {**os.environ, **_GIT_ENV, **(env_extra or {})}
return subprocess.run(
["pwsh", "-NoProfile", "-File", str(script), *args],
[exe, "-NoProfile", "-File", str(script), *args],
cwd=cwd,
capture_output=True,
text=True,
Expand All @@ -179,7 +186,7 @@ def test_manifest_validates(self):

m = ExtensionManifest(EXT_DIR / "extension.yml")
assert m.id == "git"
assert m.version == "1.0.3"
assert m.version == "1.0.4"

def test_manifest_commands(self):
"""Manifest declares expected commands."""
Expand Down Expand Up @@ -319,6 +326,80 @@ def test_skips_if_already_git_repo(self, tmp_path: Path):
assert result.returncode == 0


@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 TestInitializeRepoPowerShellStderr:
"""git warnings on stderr must not fail initialize-repo.ps1.
With $ErrorActionPreference = 'Stop', Windows PowerShell 5.1 turns every
line a native command writes to redirected stderr into a terminating
error, even when the command exits 0. PowerShell 7 does not, so only the
windows-powershell-5.1 case can reproduce it.
"""

def test_crlf_warnings_do_not_abort_initial_commit(self, tmp_path: Path, exe: str):
"""LF files with core.autocrlf=true still get the initial commit."""
project = _setup_project(tmp_path / "proj", git=False)
(project / "notes.txt").write_bytes(b"line one\nline two\n")
env = {
"GIT_CONFIG_COUNT": "1",
"GIT_CONFIG_KEY_0": "core.autocrlf",
"GIT_CONFIG_VALUE_0": "true",
}

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

assert result.returncode == 0, result.stdout + result.stderr
assert "[OK] Git repository initialized" in result.stdout
log = subprocess.run(
["git", "log", "--format=%s"],
cwd=project, capture_output=True, text=True,
)
assert log.stdout.strip() == "[Spec Kit] Initial commit"

def test_commit_failure_is_still_reported(self, tmp_path: Path, exe: str):
"""A failing git commit still exits 1 and leaves no commit behind."""
project = _setup_project(tmp_path / "proj", git=False)
hooks = tmp_path / "hooks"
hooks.mkdir()
hook = hooks / "pre-commit"
hook.write_bytes(b'#!/bin/sh\necho "pre-commit: rejected" >&2\nexit 1\n')
hook.chmod(0o755)
# autocrlf=false keeps the hook's message the only stderr output.
env = {
"GIT_CONFIG_COUNT": "2",
"GIT_CONFIG_KEY_0": "core.autocrlf",
"GIT_CONFIG_VALUE_0": "false",
"GIT_CONFIG_KEY_1": "core.hooksPath",
"GIT_CONFIG_VALUE_1": str(hooks),
}

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

assert result.returncode == 1
assert "pre-commit: rejected" in result.stdout + result.stderr
commits = subprocess.run(
["git", "rev-list", "--all", "--count"],
cwd=project, capture_output=True, text=True,
)
assert commits.stdout.strip() == "0"


# ── create-new-feature-branch.sh Tests ──────────────────────────────────────────────


Expand Down
Loading