Repository navigation
fix(extensions): keep git warnings from failing initialize-repo.ps1 on Windows PowerShell 5.1 - #5252
Merged
Conversation
…n Windows PowerShell 5.1 initialize-repo.ps1 runs git init, git add and git commit with 2>&1 under $ErrorActionPreference = 'Stop' and checks $LASTEXITCODE. Windows PowerShell 5.1 turns every line a native command writes to redirected stderr into a terminating error under 'Stop', even when the command exits 0. With Git for Windows' default core.autocrlf=true, git add warns "LF will be replaced by CRLF" for the LF files Spec Kit writes, so the mandatory before_constitution hook exits 1 after git init but before the initial commit, leaving a stale .git/index.lock. A rerun then skips because the repository already exists. Relax $ErrorActionPreference to 'Continue' around those git calls and restore it afterwards, as auto-commit.ps1 already does (github#2258). Failures are still detected through $LASTEXITCODE. PowerShell 7 does not apply $ErrorActionPreference to native stderr, so it was not affected. Bump the git extension to 1.0.4. Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues require changes before approval.
No open issues 🎉
What changed in this PR
Fixes Git extension initialization on Windows PowerShell 5.1 so harmless Git warnings no longer abort the initial commit, following the existing auto-commit.ps1 approach.
Changes:
- Temporarily relaxes error handling around initialization commands, restores it afterward, and preserves exit-code checks for real failures.
- Adds warning-success and commit-failure tests for PowerShell 7 and Windows PowerShell 5.1.
- Bumps the Git extension to version 1.0.4.
The PR reports before-and-after regression results on Windows; these were not independently rerun.
| File | Description |
|---|---|
tests/extensions/git/test_git_extension.py |
Adds selectable PowerShell hosts and initialization regression tests; updates the expected version. |
extensions/git/scripts/powershell/initialize-repo.ps1 |
Prevents warnings from terminating initialization and restores the error preference in finally. |
extensions/git/extension.yml |
Bumps the extension version to 1.0.4. |
extensions/catalog.json |
Updates the catalog version to match the manifest. |
Review effort: Balanced (auto)
Collaborator
|
Thank you! |
kevinnguyenhoang91
pushed a commit
to kevinnguyenhoang91/spec-kit
that referenced
this pull request
Nov 10, 2026
…n Windows PowerShell 5.1 (github#5252) initialize-repo.ps1 runs git init, git add and git commit with 2>&1 under $ErrorActionPreference = 'Stop' and checks $LASTEXITCODE. Windows PowerShell 5.1 turns every line a native command writes to redirected stderr into a terminating error under 'Stop', even when the command exits 0. With Git for Windows' default core.autocrlf=true, git add warns "LF will be replaced by CRLF" for the LF files Spec Kit writes, so the mandatory before_constitution hook exits 1 after git init but before the initial commit, leaving a stale .git/index.lock. A rerun then skips because the repository already exists. Relax $ErrorActionPreference to 'Continue' around those git calls and restore it afterwards, as auto-commit.ps1 already does (github#2258). Failures are still detected through $LASTEXITCODE. PowerShell 7 does not apply $ErrorActionPreference to native stderr, so it was not affected. Bump the git extension to 1.0.4. Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Windows PowerShell 5.1, the git extension's
initialize-repo.ps1fails whenever git writes a warning. The script runsgit init,git add .andgit commitwith2>&1under$ErrorActionPreference = 'Stop', and 5.1 turns each line a native command writes to redirected stderr into a terminating error, even when git exits 0. With Git for Windows' defaultcore.autocrlf=true,git add .warnsLF will be replaced by CRLFfor the LF files Spec Kit writes, so the mandatorybefore_constitutionhook stops with[specify] Error: warning: in the working copy of ...aftergit initbut before the initial commit.That leaves the project in a bad state. The interrupted
git addleaves.git/index.lockbehind, so latergit addcalls fail withUnable to create '.git/index.lock': File existsuntil the lock is deleted by hand. A rerun printsGit repository already initialized; skipping, so the initial commit never happens. #2680 shows Claude Code on Windows running this script under 5.1 from/speckit-constitution. PowerShell 7.2+ doesn't apply$ErrorActionPreferenceto native stderr, and the Bash and Python twins only check exit codes, so they are not affected.This PR relaxes
$ErrorActionPreferencetoContinuearound those three git calls and restores it in afinally, asauto-commit.ps1has done since #2258. Real failures are still caught by the existing$LASTEXITCODEchecks.Also in this PR:
tests/extensions/git/test_git_extension.py:_run_pwshtakes anexeargument, and a newTestInitializeRepoPowerShellStderrclass runs underpwshand Windows PowerShell 5.1, followingTestResolveTasksPowerShellParity. The positive test adds an LF file withcore.autocrlf=trueand expects exit 0 and the initial commit. The negative test uses a pre-commit hook that rejects the commit and expects exit 1, the hook's message and no commit. The 5.1 cases skip off Windows;windows-latesthaspowershell.exe, so CI will run them there.extension.yml,catalog.jsonand the manifest test, for the version guard.Testing
Windows 11, Windows PowerShell 5.1.26100, PowerShell 7.6.9, Git for Windows 2.45.1, Python 3.14.
pytest tests/extensions/git/test_git_extension.py::TestInitializeRepoPowerShellStderrwith the script as onmain: 1 failed, 3 passed.test_crlf_warnings_do_not_abort_initial_commit[windows-powershell-5.1]fails with[specify] Error: warning: in the working copy of '.specify/extensions/git/extension.yml', LF will be replaced by CRLF the next time Git touches itandassert 1 == 0.This branch: 4 passed.
tests/extensions/git/andtests/test_ps1_encoding.py: 85 passed, 119 skipped. The Bash tests skip here becausebashresolves to the WSL launcher.tests/extensions/git/with apwsh.execopy ofpowershell.exefirst on PATH, so every PowerShell test there runs on 5.1: 73 passed, 119 skipped.tests/contract/: 167 passed.uvx [email protected] check src tests: clean.check_extension_version_bump.py: all invariants hold.Tested locally with
uv run specify --helpRan existing tests with
uv sync && uv run pytestTested with a sample project (if applicable)
Manual test results
Agent: Claude Code (Claude Opus 5.5), autonomous | OS/Shell: Windows 11 / Windows PowerShell 5.1, PowerShell 7.6.9
Projects were made from this branch with
specify init <dir> --integration claude --script ps --extension git --ignore-agent-tools --non-interactive. For themaincolumn, the installedinitialize-repo.ps1was replaced with the one onmain. The script line thatspeckit.git.initializetells the agent to run was run directly from the project root withpowershell.exe -NoProfile -Fileorpwsh -NoProfile -File, not from an interactive agent session.main/speckit.git.initialize, Windows PowerShell 5.1.git/index.lockleft. A rerun skips and still has no commit.[OK] Git repository initialized, 1 commit, clean tree/speckit.git.initialize, PowerShell 7.6.9AI Disclosure
AI disclosure: Claude Code (Claude Opus 5.5, max reasoning effort, autonomous) found the bug, wrote the fix, tests and this description, and ran the checks above on behalf of Bortlesboat; the commit has an
Assisted-bytrailer.