From 00647fd433705f448a77e34713afac2907c09664 Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sat, 21 Mar 2026 19:16:27 +0100 Subject: [PATCH 1/9] fix(scripts): prioritize .specify over git for repo root detection When spec-kit is initialized in a subdirectory that doesn't have its own .git, but a parent directory does, spec-kit was incorrectly using the parent's git repository root. This caused specs to be created in the wrong location. The fix changes repo root detection to prioritize .specify directory over git rev-parse, ensuring spec-kit respects its own initialization boundary rather than inheriting a parent git repo. Fixes #1932 Co-Authored-By: Claude Opus 4.5 --- scripts/bash/common.sh | 40 ++++++++++++++++++---- scripts/bash/create-new-feature.sh | 17 ++++++---- scripts/powershell/common.ps1 | 41 ++++++++++++++++++----- scripts/powershell/create-new-feature.ps1 | 28 +++++++--------- 4 files changed, 88 insertions(+), 38 deletions(-) diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index 826e740f00..3eca83338b 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -1,15 +1,39 @@ #!/usr/bin/env bash # Common functions and variables for all scripts -# Get repository root, with fallback for non-git repositories +# Find repository root by searching upward for .specify directory +# This is the primary marker for spec-kit projects +find_specify_root() { + local dir="${1:-$(pwd)}" + while [ "$dir" != "/" ]; do + if [ -d "$dir/.specify" ]; then + echo "$dir" + return 0 + fi + dir="$(dirname "$dir")" + done + return 1 +} + +# Get repository root, prioritizing .specify directory over git +# This prevents using a parent git repo when spec-kit is initialized in a subdirectory get_repo_root() { + # First, look for .specify directory (spec-kit's own marker) + local specify_root + if specify_root=$(find_specify_root); then + echo "$specify_root" + return + fi + + # Fallback to git if no .specify found if git rev-parse --show-toplevel >/dev/null 2>&1; then git rev-parse --show-toplevel - else - # Fall back to script location for non-git repos - local script_dir="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - (cd "$script_dir/../../.." && pwd) + return fi + + # Final fallback to script location for non-git repos + local script_dir="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + (cd "$script_dir/../../.." && pwd) } # Get current branch, with fallback for non-git repositories @@ -57,9 +81,11 @@ get_current_branch() { echo "main" # Final fallback } -# Check if we have git available +# Check if we have git available at the spec-kit root level +# Returns true only if the .specify root has its own .git directory has_git() { - git rev-parse --show-toplevel >/dev/null 2>&1 + local repo_root=$(get_repo_root) + [ -d "$repo_root/.git" ] } check_feature_branch() { diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.sh index 58c5c86c48..1cfdd7c409 100644 --- a/scripts/bash/create-new-feature.sh +++ b/scripts/bash/create-new-feature.sh @@ -162,21 +162,24 @@ clean_branch_name() { echo "$name" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9]/-/g' | sed 's/-\+/-/g' | sed 's/^-//' | sed 's/-$//' } -# Resolve repository root. Prefer git information when available, but fall back -# to searching for repository markers so the workflow still functions in repositories that -# were initialised with --no-git. +# Resolve repository root using common.sh functions which prioritize .specify over git SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/common.sh" -if git rev-parse --show-toplevel >/dev/null 2>&1; then - REPO_ROOT=$(git rev-parse --show-toplevel) - HAS_GIT=true -else +REPO_ROOT=$(get_repo_root) +if [ -z "$REPO_ROOT" ]; then + # Fallback to local find_repo_root if common.sh couldn't find it REPO_ROOT="$(find_repo_root "$SCRIPT_DIR")" if [ -z "$REPO_ROOT" ]; then echo "Error: Could not determine repository root. Please run this script from within the repository." >&2 exit 1 fi +fi + +# Check if git is available at this repo root (not a parent) +if has_git; then + HAS_GIT=true +else HAS_GIT=false fi diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index 3d6a77f295..d4db7a2e69 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -1,7 +1,34 @@ #!/usr/bin/env pwsh # Common PowerShell functions analogous to common.sh +# Find repository root by searching upward for .specify directory +# This is the primary marker for spec-kit projects +function Find-SpecifyRoot { + param([string]$StartDir = (Get-Location).Path) + + $current = $StartDir + while ($true) { + if (Test-Path (Join-Path $current ".specify")) { + return $current + } + $parent = Split-Path $current -Parent + if ([string]::IsNullOrEmpty($parent) -or $parent -eq $current) { + return $null + } + $current = $parent + } +} + +# Get repository root, prioritizing .specify directory over git +# This prevents using a parent git repo when spec-kit is initialized in a subdirectory function Get-RepoRoot { + # First, look for .specify directory (spec-kit's own marker) + $specifyRoot = Find-SpecifyRoot + if ($specifyRoot) { + return $specifyRoot + } + + # Fallback to git if no .specify found try { $result = git rev-parse --show-toplevel 2>$null if ($LASTEXITCODE -eq 0) { @@ -10,8 +37,8 @@ function Get-RepoRoot { } catch { # Git command failed } - - # Fall back to script location for non-git repos + + # Final fallback to script location for non-git repos return (Resolve-Path (Join-Path $PSScriptRoot "../../..")).Path } @@ -58,13 +85,11 @@ function Get-CurrentBranch { return "main" } +# Check if we have git available at the spec-kit root level +# Returns true only if the .specify root has its own .git directory function Test-HasGit { - try { - git rev-parse --show-toplevel 2>$null | Out-Null - return ($LASTEXITCODE -eq 0) - } catch { - return $false - } + $repoRoot = Get-RepoRoot + return (Test-Path (Join-Path $repoRoot ".git")) } function Test-FeatureBranch { diff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1 index 31acbe2958..5c1778e728 100644 --- a/scripts/powershell/create-new-feature.ps1 +++ b/scripts/powershell/create-new-feature.ps1 @@ -135,27 +135,23 @@ function ConvertTo-CleanBranchName { return $Name.ToLower() -replace '[^a-z0-9]', '-' -replace '-{2,}', '-' -replace '^-', '' -replace '-$', '' } -$fallbackRoot = (Find-RepositoryRoot -StartDir $PSScriptRoot) -if (-not $fallbackRoot) { - Write-Error "Error: Could not determine repository root. Please run this script from within the repository." - exit 1 -} - -# Load common functions (includes Resolve-Template) +# Load common functions (includes Get-RepoRoot, Test-HasGit, Resolve-Template) . "$PSScriptRoot/common.ps1" -try { - $repoRoot = git rev-parse --show-toplevel 2>$null - if ($LASTEXITCODE -eq 0) { - $hasGit = $true - } else { - throw "Git not available" +# Use common.ps1 functions which prioritize .specify over git +$repoRoot = Get-RepoRoot +if (-not $repoRoot) { + # Fallback to local Find-RepositoryRoot if common.ps1 couldn't find it + $repoRoot = (Find-RepositoryRoot -StartDir $PSScriptRoot) + if (-not $repoRoot) { + Write-Error "Error: Could not determine repository root. Please run this script from within the repository." + exit 1 } -} catch { - $repoRoot = $fallbackRoot - $hasGit = $false } +# Check if git is available at this repo root (not a parent) +$hasGit = Test-HasGit + Set-Location $repoRoot $specsDir = Join-Path $repoRoot 'specs' From 8a9ce68d17cd9f6bd8bda7c8910850d4de4cf514 Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sat, 21 Mar 2026 19:51:18 +0100 Subject: [PATCH 2/9] fix: address code review feedback - Normalize paths in find_specify_root to prevent infinite loop with relative paths - Use -PathType Container in PowerShell to only match .specify directories - Improve has_git/Test-HasGit to check git command availability and validate work tree - Handle git worktrees/submodules where .git can be a file - Remove dead fallback code in create-new-feature scripts Co-Authored-By: Claude Opus 4.5 --- scripts/bash/common.sh | 16 +++++++++++--- scripts/bash/create-new-feature.sh | 8 ------- scripts/powershell/common.ps1 | 26 +++++++++++++++++++---- scripts/powershell/create-new-feature.ps1 | 8 ------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index 3eca83338b..762754c734 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -5,11 +5,15 @@ # This is the primary marker for spec-kit projects find_specify_root() { local dir="${1:-$(pwd)}" - while [ "$dir" != "/" ]; do + # Normalize to absolute path to prevent infinite loop with relative paths + dir="$(cd "$dir" 2>/dev/null && pwd)" || return 1 + local prev_dir="" + while [ "$dir" != "/" ] && [ "$dir" != "$prev_dir" ]; do if [ -d "$dir/.specify" ]; then echo "$dir" return 0 fi + prev_dir="$dir" dir="$(dirname "$dir")" done return 1 @@ -82,10 +86,16 @@ get_current_branch() { } # Check if we have git available at the spec-kit root level -# Returns true only if the .specify root has its own .git directory +# Returns true only if git is installed and the repo root is inside a git work tree +# Handles both regular repos (.git directory) and worktrees/submodules (.git file) has_git() { local repo_root=$(get_repo_root) - [ -d "$repo_root/.git" ] + # First check if git command is available + command -v git >/dev/null 2>&1 || return 1 + # Check if .git exists (directory or file for worktrees/submodules) + [ -e "$repo_root/.git" ] || return 1 + # Verify it's actually a valid git work tree + git -C "$repo_root" rev-parse --is-inside-work-tree >/dev/null 2>&1 } check_feature_branch() { diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.sh index 1cfdd7c409..70a04bcf88 100644 --- a/scripts/bash/create-new-feature.sh +++ b/scripts/bash/create-new-feature.sh @@ -167,14 +167,6 @@ SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/common.sh" REPO_ROOT=$(get_repo_root) -if [ -z "$REPO_ROOT" ]; then - # Fallback to local find_repo_root if common.sh couldn't find it - REPO_ROOT="$(find_repo_root "$SCRIPT_DIR")" - if [ -z "$REPO_ROOT" ]; then - echo "Error: Could not determine repository root. Please run this script from within the repository." >&2 - exit 1 - fi -fi # Check if git is available at this repo root (not a parent) if has_git; then diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index d4db7a2e69..cbe10e9141 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -6,9 +6,12 @@ function Find-SpecifyRoot { param([string]$StartDir = (Get-Location).Path) - $current = $StartDir + # Normalize to absolute path to prevent issues with relative paths + $current = (Resolve-Path $StartDir -ErrorAction SilentlyContinue)?.Path + if (-not $current) { return $null } + while ($true) { - if (Test-Path (Join-Path $current ".specify")) { + if (Test-Path -Path (Join-Path $current ".specify") -PathType Container) { return $current } $parent = Split-Path $current -Parent @@ -86,10 +89,25 @@ function Get-CurrentBranch { } # Check if we have git available at the spec-kit root level -# Returns true only if the .specify root has its own .git directory +# Returns true only if git is installed and the repo root is inside a git work tree +# Handles both regular repos (.git directory) and worktrees/submodules (.git file) function Test-HasGit { $repoRoot = Get-RepoRoot - return (Test-Path (Join-Path $repoRoot ".git")) + # First check if git command is available + if (-not (Get-Command git -ErrorAction SilentlyContinue)) { + return $false + } + # Check if .git exists (directory or file for worktrees/submodules) + if (-not (Test-Path (Join-Path $repoRoot ".git"))) { + return $false + } + # Verify it's actually a valid git work tree + try { + $null = git -C $repoRoot rev-parse --is-inside-work-tree 2>$null + return ($LASTEXITCODE -eq 0) + } catch { + return $false + } } function Test-FeatureBranch { diff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1 index 5c1778e728..6175907b08 100644 --- a/scripts/powershell/create-new-feature.ps1 +++ b/scripts/powershell/create-new-feature.ps1 @@ -140,14 +140,6 @@ function ConvertTo-CleanBranchName { # Use common.ps1 functions which prioritize .specify over git $repoRoot = Get-RepoRoot -if (-not $repoRoot) { - # Fallback to local Find-RepositoryRoot if common.ps1 couldn't find it - $repoRoot = (Find-RepositoryRoot -StartDir $PSScriptRoot) - if (-not $repoRoot) { - Write-Error "Error: Could not determine repository root. Please run this script from within the repository." - exit 1 - } -} # Check if git is available at this repo root (not a parent) $hasGit = Test-HasGit From 93cef2e3c58dd60b0aa64a3edc92f4e469af8a2d Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sat, 21 Mar 2026 23:08:50 +0100 Subject: [PATCH 3/9] fix: check .specify before termination in find_specify_root Fixes edge case where project root is at filesystem root (common in containers). The loop now checks for .specify before checking the termination condition. Co-Authored-By: Claude Opus 4.5 --- scripts/bash/common.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index 762754c734..4c7848a57a 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -8,11 +8,15 @@ find_specify_root() { # Normalize to absolute path to prevent infinite loop with relative paths dir="$(cd "$dir" 2>/dev/null && pwd)" || return 1 local prev_dir="" - while [ "$dir" != "/" ] && [ "$dir" != "$prev_dir" ]; do + while true; do if [ -d "$dir/.specify" ]; then echo "$dir" return 0 fi + # Stop if we've reached filesystem root or dirname stops changing + if [ "$dir" = "/" ] || [ "$dir" = "$prev_dir" ]; then + break + fi prev_dir="$dir" dir="$(dirname "$dir")" done From 334df41aba3de301cb483a6a4bbb337115d96a10 Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sun, 22 Mar 2026 00:16:29 +0100 Subject: [PATCH 4/9] fix: scope git operations to spec-kit root & remove unused helpers - get_current_branch now uses has_git check and runs git with -C to prevent using parent git repo branch names in .specify-only projects - Same fix applied to PowerShell Get-CurrentBranch - Removed unused find_repo_root() from create-new-feature.sh - Removed unused Find-RepositoryRoot from create-new-feature.ps1 Co-Authored-By: Claude Opus 4.5 --- scripts/bash/common.sh | 8 ++++---- scripts/bash/create-new-feature.sh | 13 ------------ scripts/powershell/common.ps1 | 22 +++++++++++---------- scripts/powershell/create-new-feature.ps1 | 24 ----------------------- 4 files changed, 16 insertions(+), 51 deletions(-) diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index 4c7848a57a..48d1f4c317 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -52,14 +52,14 @@ get_current_branch() { return fi - # Then check git if available - if git rev-parse --abbrev-ref HEAD >/dev/null 2>&1; then - git rev-parse --abbrev-ref HEAD + # Then check git if available at the spec-kit root (not parent) + local repo_root=$(get_repo_root) + if has_git; then + git -C "$repo_root" rev-parse --abbrev-ref HEAD return fi # For non-git repos, try to find the latest feature directory - local repo_root=$(get_repo_root) local specs_dir="$repo_root/specs" if [[ -d "$specs_dir" ]]; then diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.sh index 70a04bcf88..f2847c7bf3 100644 --- a/scripts/bash/create-new-feature.sh +++ b/scripts/bash/create-new-feature.sh @@ -74,19 +74,6 @@ if [ -z "$FEATURE_DESCRIPTION" ]; then exit 1 fi -# Function to find the repository root by searching for existing project markers -find_repo_root() { - local dir="$1" - while [ "$dir" != "/" ]; do - if [ -d "$dir/.git" ] || [ -d "$dir/.specify" ]; then - echo "$dir" - return 0 - fi - dir="$(dirname "$dir")" - done - return 1 -} - # Function to get highest number from specs directory get_highest_from_specs() { local specs_dir="$1" diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index cbe10e9141..0e63dab68c 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -50,19 +50,21 @@ function Get-CurrentBranch { if ($env:SPECIFY_FEATURE) { return $env:SPECIFY_FEATURE } - - # Then check git if available - try { - $result = git rev-parse --abbrev-ref HEAD 2>$null - if ($LASTEXITCODE -eq 0) { - return $result + + # Then check git if available at the spec-kit root (not parent) + $repoRoot = Get-RepoRoot + if (Test-HasGit) { + try { + $result = git -C $repoRoot rev-parse --abbrev-ref HEAD 2>$null + if ($LASTEXITCODE -eq 0) { + return $result + } + } catch { + # Git command failed } - } catch { - # Git command failed } - + # For non-git repos, try to find the latest feature directory - $repoRoot = Get-RepoRoot $specsDir = Join-Path $repoRoot "specs" if (Test-Path $specsDir) { diff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1 index 6175907b08..b1fdd0f152 100644 --- a/scripts/powershell/create-new-feature.ps1 +++ b/scripts/powershell/create-new-feature.ps1 @@ -41,30 +41,6 @@ if ([string]::IsNullOrWhiteSpace($featureDesc)) { exit 1 } -# Resolve repository root. Prefer git information when available, but fall back -# to searching for repository markers so the workflow still functions in repositories that -# were initialized with --no-git. -function Find-RepositoryRoot { - param( - [string]$StartDir, - [string[]]$Markers = @('.git', '.specify') - ) - $current = Resolve-Path $StartDir - while ($true) { - foreach ($marker in $Markers) { - if (Test-Path (Join-Path $current $marker)) { - return $current - } - } - $parent = Split-Path $current -Parent - if ($parent -eq $current) { - # Reached filesystem root without finding markers - return $null - } - $current = $parent - } -} - function Get-HighestNumberFromSpecs { param([string]$SpecsDir) From 43b3d558d35672403a8588fa5a9636b080ddb4cc Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sun, 22 Mar 2026 00:35:49 +0100 Subject: [PATCH 5/9] fix: use cd -- to handle paths starting with dash Prevents cd from interpreting directory names like -P or -L as options. Co-Authored-By: Claude Opus 4.5 --- scripts/bash/common.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index 48d1f4c317..d13265fcdc 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -6,7 +6,8 @@ find_specify_root() { local dir="${1:-$(pwd)}" # Normalize to absolute path to prevent infinite loop with relative paths - dir="$(cd "$dir" 2>/dev/null && pwd)" || return 1 + # Use -- to handle paths starting with - (e.g., -P, -L) + dir="$(cd -- "$dir" 2>/dev/null && pwd)" || return 1 local prev_dir="" while true; do if [ -d "$dir/.specify" ]; then From a2c7c5b6e9899ef37f5254ae3bb4834558169f2c Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sun, 22 Mar 2026 10:46:20 +0100 Subject: [PATCH 6/9] fix: check git command exists before calling get_repo_root in has_git Avoids unnecessary work when git isn't installed since get_repo_root may internally call git rev-parse. Co-Authored-By: Claude Opus 4.5 --- scripts/bash/common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index d13265fcdc..9b54839039 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -94,9 +94,9 @@ get_current_branch() { # Returns true only if git is installed and the repo root is inside a git work tree # Handles both regular repos (.git directory) and worktrees/submodules (.git file) has_git() { - local repo_root=$(get_repo_root) - # First check if git command is available + # First check if git command is available (before calling get_repo_root which may use git) command -v git >/dev/null 2>&1 || return 1 + local repo_root=$(get_repo_root) # Check if .git exists (directory or file for worktrees/submodules) [ -e "$repo_root/.git" ] || return 1 # Verify it's actually a valid git work tree From 6df0d5f4fbe13474b0d62156499d312808c7fed8 Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sun, 22 Mar 2026 12:56:19 +0100 Subject: [PATCH 7/9] 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 --- scripts/powershell/common.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index 0e63dab68c..42cca9218b 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -7,11 +7,12 @@ function Find-SpecifyRoot { param([string]$StartDir = (Get-Location).Path) # Normalize to absolute path to prevent issues with relative paths - $current = (Resolve-Path $StartDir -ErrorAction SilentlyContinue)?.Path + # Use -LiteralPath to handle paths with wildcard characters ([, ], *, ?) + $current = (Resolve-Path -LiteralPath $StartDir -ErrorAction SilentlyContinue)?.Path if (-not $current) { return $null } while ($true) { - if (Test-Path -Path (Join-Path $current ".specify") -PathType Container) { + if (Test-Path -LiteralPath (Join-Path $current ".specify") -PathType Container) { return $current } $parent = Split-Path $current -Parent @@ -94,11 +95,11 @@ function Get-CurrentBranch { # Returns true only if git is installed and the repo root is inside a git work tree # Handles both regular repos (.git directory) and worktrees/submodules (.git file) function Test-HasGit { - $repoRoot = Get-RepoRoot - # First check if git command is available + # First check if git command is available (before calling Get-RepoRoot which may use git) if (-not (Get-Command git -ErrorAction SilentlyContinue)) { return $false } + $repoRoot = Get-RepoRoot # Check if .git exists (directory or file for worktrees/submodules) if (-not (Test-Path (Join-Path $repoRoot ".git"))) { return $false From 028ac2ead93496518bc72f6b4079867b6ddb8ba4 Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Sun, 22 Mar 2026 14:59:30 +0100 Subject: [PATCH 8/9] fix(powershell): use LiteralPath for .git check in Test-HasGit Prevents Test-Path from treating wildcard characters in paths as globs. Co-Authored-By: Claude Opus 4.5 --- scripts/powershell/common.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index 42cca9218b..4730d2a221 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -101,7 +101,8 @@ function Test-HasGit { } $repoRoot = Get-RepoRoot # Check if .git exists (directory or file for worktrees/submodules) - if (-not (Test-Path (Join-Path $repoRoot ".git"))) { + # Use -LiteralPath to handle paths with wildcard characters + if (-not (Test-Path -LiteralPath (Join-Path $repoRoot ".git"))) { return $false } # Verify it's actually a valid git work tree From b49de4d76d76d77a1d845b9124fff795cca1f51e Mon Sep 17 00:00:00 2001 From: iamaeroplane Date: Tue, 24 Mar 2026 09:49:51 +0100 Subject: [PATCH 9/9] fix(powershell): use LiteralPath in Get-RepoRoot fallback Prevents Resolve-Path from treating wildcard characters as patterns. Co-Authored-By: Claude Opus 4.5 --- scripts/powershell/common.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index 4730d2a221..1deb895c7c 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -43,7 +43,8 @@ function Get-RepoRoot { } # Final fallback to script location for non-git repos - return (Resolve-Path (Join-Path $PSScriptRoot "../../..")).Path + # Use -LiteralPath to handle paths with wildcard characters + return (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "../../..")).Path } function Get-CurrentBranch {