Repository navigation
fix(powershell): treat bracketed project paths literally in the git extension - #5404
Open
adityajai119 wants to merge 1 commit into
Open
adityajai119 wants to merge 1 commit into
adityajai119 wants to merge 1 commit into
Conversation
…xtension The git extension's PowerShell scripts passed project paths to Resolve-Path, Test-Path, Set-Location, Get-ChildItem, Get-Content, Remove-Item and Select-String without -LiteralPath, so brackets in the path were read as wildcards. initialize-repo.ps1, create-new-feature-branch.ps1 and auto-commit.ps1 stopped in Find-ProjectRoot; behind that, a new feature was numbered 001 again, git-config.yml and -MessageFile were not read, and an event set to enabled: false was committed under auto_commit.default: true. Bump the git extension to 1.0.5. Fixes github#5403 Assisted-by: OpenCode (model: Claude Opus 5.5, autonomous)
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes comprehensively address bracketed-path wildcard handling across the affected PowerShell operations and add regression coverage for PowerShell 7 and Windows PowerShell 5.1.
No open issues 🎉
What changed in this PR
Fixes the Git extension’s PowerShell scripts so project and configuration paths containing [ or ] are treated literally rather than as wildcard patterns, with regression coverage and a version update.
Changes:
- Applies
-LiteralPathto project discovery, repository checks, configuration reads, feature numbering, message-file handling, and related filesystem operations. - Adds regression tests for bracketed project paths across PowerShell 7 and Windows PowerShell 5.1.
- Bumps the Git extension from
1.0.4to1.0.5in the manifest and catalog.
| File | Description |
|---|---|
| tests/extensions/git/test_git_extension.py | Adds bracketed-path regression tests for PowerShell 7 and Windows PowerShell 5.1 and updates the manifest version assertion. |
| extensions/git/scripts/powershell/initialize-repo.ps1 | Uses literal path handling for repository discovery, configuration lookup, and directory changes. |
| extensions/git/scripts/powershell/git-common.ps1 | Uses literal path handling when detecting the .git directory. |
| extensions/git/scripts/powershell/create-new-feature-branch.ps1 | Uses literal paths for spec discovery, project-root resolution, script loading, configuration access, and directory changes. |
| extensions/git/scripts/powershell/auto-commit.ps1 | Uses literal paths for message files, project-root resolution, configuration reads, and event detection. |
| extensions/git/extension.yml | Bumps the Git extension version to 1.0.5. |
| extensions/catalog.json | Updates the catalog entry to version 1.0.5. |
Review effort: Lite (auto)
4 of 5 tasks
This branch has not been deployed
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
Fixes #5403.
This is the same
-LiteralPathfix as #5399, applied to the git extension's PowerShell scripts (extensions/git/scripts/powershell/). In a project whose path contains[or](for exampleapp [v2]), these scripts read the brackets as wildcards:initialize-repo.ps1,create-new-feature-branch.ps1andauto-commit.ps1all stop inFind-ProjectRoot:Resolve-Path $StartDirreturns nothing and the nextJoin-Pathfails with "Cannot bind argument to parameter 'Path' because it is null". The repository is not initialized, no feature branch is created, and nothing is auto-committed.Get-HighestNumberFromSpecssees no existingspecs/folders, so a new feature is numbered001again.auto-commit.ps1withauto_commit.default: truechecks for the event's own key withSelect-String -Path, finds no file, and commits an event set toenabled: false.initialize-repo.ps1andauto-commit.ps1do not seegit-config.yml, andauto-commit.ps1reports an existing-MessageFileas missing.create-new-feature-branch.ps1does not findgit-common.ps1, andTest-HasGitthere reports no repository.This PR adds
-LiteralPathto each of those calls (23 lines across the four scripts) and bumps the git extension to 1.0.5 inextension.ymlandextensions/catalog.json, as the version guard requires.Join-PathandSplit-Pathonly work on strings here, so they are unchanged.Overlap with open PRs: #5390 adds
-Encoding UTF8to some of the sameGet-Contentlines, and #5006, #5213 and #5390 also bump the git extension version, so whichever merges later needs a small rebase.Testing
.\.venv\Scripts\specify.exe --help.\.venv\Scripts\python.exe -m pytest tests -q, using the affected test paths:tests/extensions/git,tests/test_timestamp_branches.pyandtests/contractgive 278 passed, 177 skipped (176 skips are bash cases, which skip on this Windows machine, and 1 is POSIX-only)New
TestPowerShellBracketedProjectPathintests/extensions/git/test_git_extension.pyruns in a project namedproj [v2]on bothpwshand Windows PowerShell 5.1 (6 tests, 12 cases):initialize-repo.ps1commits withinit_commit_messagefromgit-config.yml;create-new-feature-branch.ps1creates002-payment-exportnext to an existingspecs/001-login-page;git-common.ps1and exits 0;Test-HasGit -RepoRootingit-common.ps1finds the repository;auto-commit.ps1commits with the-MessageFiletext and deletes the file;default: true, an event set toenabled: falsemakes no commit.Results on Windows PowerShell 5.1.26100 and a portable PowerShell 7.7.0:
main's scripts: 12 failed;Get-ChildItemline fails with'001-payment-export' == '002-payment-export', theSelect-Stringline with'2' == '1'(the disabled event was committed), and theRemove-Itemline leaves the message file behind.A note on the
create-new-feature-branch.ps1test: Windows PowerShell 5.1 started in a directory whose name contains brackets begins in$PSHOMEinstead of that directory (PowerShell 7.7 does not). CoreGet-RepoRootthen falls back to the script location, which finds the project in the layoutspecify initcreates (.specify/scripts/powershell/common.ps1). So the test adds that layout; with only_setup_project's source-checkout layout, the fallback lands one level above the project.Sample project, from v1.4.0 and from
main(979b0a3):specify init 'app [v2]' --integration codex --script ps --ignore-agent-tools --non-interactive,specify extension add git, then the three scripts under Windows PowerShell 5.1. With the shipped scripts all three exit 1. With this PR's scripts they print[OK] Git repository initializedand{"BRANCH_NAME":"002-payment-export","FEATURE_NUM":"002"}, andauto-commit.ps1exits 0.Also ran
uvx ruff@0.15.0 check src tests(all checks passed),git diff --check(clean),.github/scripts/check_extension_version_bump.py origin/main HEAD(all invariants hold), and parsed the four scripts with the Windows PowerShell 5.1 parser (no errors).AI Disclosure
AI disclosure: OpenCode with Claude Opus 5.5 (max reasoning effort, autonomous agent mode), acting on behalf of @adityajai119, found and reproduced the bug, wrote the fix and the tests, ran the checks above, and drafted this description. The commit carries an
Assisted-by: OpenCode (model: Claude Opus 5.5, autonomous)trailer.