Skip to content

fix(powershell): treat bracketed project paths literally in the git extension - #5404

Open
adityajai119 wants to merge 1 commit into
github:mainfrom
adityajai119:fix/5403-git-ext-bracketed-paths
Open

adityajai119 wants to merge 1 commit into
github:mainfrom
adityajai119:fix/5403-git-ext-bracketed-paths

Conversation

@adityajai119

Copy link
Copy Markdown
Contributor

Description

Fixes #5403.

This is the same -LiteralPath fix as #5399, applied to the git extension's PowerShell scripts (extensions/git/scripts/powershell/). In a project whose path contains [ or ] (for example app [v2]), these scripts read the brackets as wildcards:

  • initialize-repo.ps1, create-new-feature-branch.ps1 and auto-commit.ps1 all stop in Find-ProjectRoot: Resolve-Path $StartDir returns nothing and the next Join-Path fails 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-HighestNumberFromSpecs sees no existing specs/ folders, so a new feature is numbered 001 again.
  • auto-commit.ps1 with auto_commit.default: true checks for the event's own key with Select-String -Path, finds no file, and commits an event set to enabled: false.
  • initialize-repo.ps1 and auto-commit.ps1 do not see git-config.yml, and auto-commit.ps1 reports an existing -MessageFile as missing.
  • Without core scripts, create-new-feature-branch.ps1 does not find git-common.ps1, and Test-HasGit there reports no repository.

This PR adds -LiteralPath to each of those calls (23 lines across the four scripts) and bumps the git extension to 1.0.5 in extension.yml and extensions/catalog.json, as the version guard requires. Join-Path and Split-Path only work on strings here, so they are unchanged.

Overlap with open PRs: #5390 adds -Encoding UTF8 to some of the same Get-Content lines, and #5006, #5213 and #5390 also bump the git extension version, so whichever merges later needs a small rebase.

Testing

  • Tested locally with .\.venv\Scripts\specify.exe --help
  • Ran relevant existing tests with .\.venv\Scripts\python.exe -m pytest tests -q, using the affected test paths: tests/extensions/git, tests/test_timestamp_branches.py and tests/contract give 278 passed, 177 skipped (176 skips are bash cases, which skip on this Windows machine, and 1 is POSIX-only)
  • Tested with a sample project (if applicable)

New TestPowerShellBracketedProjectPath in tests/extensions/git/test_git_extension.py runs in a project named proj [v2] on both pwsh and Windows PowerShell 5.1 (6 tests, 12 cases):

  • initialize-repo.ps1 commits with init_commit_message from git-config.yml;
  • create-new-feature-branch.ps1 creates 002-payment-export next to an existing specs/001-login-page;
  • without core scripts, it loads git-common.ps1 and exits 0;
  • Test-HasGit -RepoRoot in git-common.ps1 finds the repository;
  • auto-commit.ps1 commits with the -MessageFile text and deletes the file;
  • with default: true, an event set to enabled: false makes no commit.

Results on Windows PowerShell 5.1.26100 and a portable PowerShell 7.7.0:

  • with main's scripts: 12 failed;
  • with this PR: 12 passed;
  • reverting a single change fails the matching test on both hosts. For example, the Get-ChildItem line fails with '001-payment-export' == '002-payment-export', the Select-String line with '2' == '1' (the disabled event was committed), and the Remove-Item line leaves the message file behind.

A note on the create-new-feature-branch.ps1 test: Windows PowerShell 5.1 started in a directory whose name contains brackets begins in $PSHOME instead of that directory (PowerShell 7.7 does not). Core Get-RepoRoot then falls back to the script location, which finds the project in the layout specify init creates (.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 initialized and {"BRANCH_NAME":"002-payment-export","FEATURE_NUM":"002"}, and auto-commit.ps1 exits 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

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

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.

…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)
@adityajai119
adityajai119 requested a review from mnriem as a code owner November 12, 2026 11:48
Copilot AI dynamic review requested due to automatic review settings November 12, 2026 11:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 -LiteralPath to 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.4 to 1.0.5 in 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)

@mnriem mnriem added the triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate label Nov 12, 2026
@mnriem
mnriem requested a dynamic review from Copilot November 12, 2026 16:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported, and the change includes targeted regression coverage for literal bracketed-path handling across supported PowerShell hosts.

No open issues 🎉

Review effort: Lite (auto)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-can-wait Verdict: valid and in-scope but deprioritized; held behind the evidence gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: git extension PowerShell scripts fail in a project whose path contains square brackets

3 participants