Skip to content

Commit 6df0d5f

Browse files
iamaeroplaneclaude
andcommitted
fix(powershell): use LiteralPath and check git before Get-RepoRoot
- Use -LiteralPath in Find-SpecifyRoot to handle paths with wildcard characters ([, ], *, ?) - Check Get-Command git before calling Get-RepoRoot in Test-HasGit to avoid unnecessary work when git isn't installed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a2c7c5b commit 6df0d5f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

scripts/powershell/common.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ function Find-SpecifyRoot {
77
param([string]$StartDir = (Get-Location).Path)
88

99
# Normalize to absolute path to prevent issues with relative paths
10-
$current = (Resolve-Path $StartDir -ErrorAction SilentlyContinue)?.Path
10+
# Use -LiteralPath to handle paths with wildcard characters ([, ], *, ?)
11+
$current = (Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue)?.Path
1112
if (-not $current) { return $null }
1213

1314
while ($true) {
14-
if (Test-Path -Path (Join-Path $current ".specify") -PathType Container) {
15+
if (Test-Path -LiteralPath (Join-Path $current ".specify") -PathType Container) {
1516
return $current
1617
}
1718
$parent = Split-Path $current -Parent
@@ -94,11 +95,11 @@ function Get-CurrentBranch {
9495
# Returns true only if git is installed and the repo root is inside a git work tree
9596
# Handles both regular repos (.git directory) and worktrees/submodules (.git file)
9697
function Test-HasGit {
97-
$repoRoot = Get-RepoRoot
98-
# First check if git command is available
98+
# First check if git command is available (before calling Get-RepoRoot which may use git)
9999
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
100100
return $false
101101
}
102+
$repoRoot = Get-RepoRoot
102103
# Check if .git exists (directory or file for worktrees/submodules)
103104
if (-not (Test-Path (Join-Path $repoRoot ".git"))) {
104105
return $false

0 commit comments

Comments
 (0)