Skip to content

Commit 334df41

Browse files
iamaeroplaneclaude
andcommitted
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 <noreply@anthropic.com>
1 parent 93cef2e commit 334df41

4 files changed

Lines changed: 16 additions & 51 deletions

File tree

scripts/bash/common.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ get_current_branch() {
5252
return
5353
fi
5454

55-
# Then check git if available
56-
if git rev-parse --abbrev-ref HEAD >/dev/null 2>&1; then
57-
git rev-parse --abbrev-ref HEAD
55+
# Then check git if available at the spec-kit root (not parent)
56+
local repo_root=$(get_repo_root)
57+
if has_git; then
58+
git -C "$repo_root" rev-parse --abbrev-ref HEAD
5859
return
5960
fi
6061

6162
# For non-git repos, try to find the latest feature directory
62-
local repo_root=$(get_repo_root)
6363
local specs_dir="$repo_root/specs"
6464

6565
if [[ -d "$specs_dir" ]]; then

scripts/bash/create-new-feature.sh

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,6 @@ if [ -z "$FEATURE_DESCRIPTION" ]; then
7474
exit 1
7575
fi
7676

77-
# Function to find the repository root by searching for existing project markers
78-
find_repo_root() {
79-
local dir="$1"
80-
while [ "$dir" != "/" ]; do
81-
if [ -d "$dir/.git" ] || [ -d "$dir/.specify" ]; then
82-
echo "$dir"
83-
return 0
84-
fi
85-
dir="$(dirname "$dir")"
86-
done
87-
return 1
88-
}
89-
9077
# Function to get highest number from specs directory
9178
get_highest_from_specs() {
9279
local specs_dir="$1"

scripts/powershell/common.ps1

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,21 @@ function Get-CurrentBranch {
5050
if ($env:SPECIFY_FEATURE) {
5151
return $env:SPECIFY_FEATURE
5252
}
53-
54-
# Then check git if available
55-
try {
56-
$result = git rev-parse --abbrev-ref HEAD 2>$null
57-
if ($LASTEXITCODE -eq 0) {
58-
return $result
53+
54+
# Then check git if available at the spec-kit root (not parent)
55+
$repoRoot = Get-RepoRoot
56+
if (Test-HasGit) {
57+
try {
58+
$result = git -C $repoRoot rev-parse --abbrev-ref HEAD 2>$null
59+
if ($LASTEXITCODE -eq 0) {
60+
return $result
61+
}
62+
} catch {
63+
# Git command failed
5964
}
60-
} catch {
61-
# Git command failed
6265
}
63-
66+
6467
# For non-git repos, try to find the latest feature directory
65-
$repoRoot = Get-RepoRoot
6668
$specsDir = Join-Path $repoRoot "specs"
6769

6870
if (Test-Path $specsDir) {

scripts/powershell/create-new-feature.ps1

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,6 @@ if ([string]::IsNullOrWhiteSpace($featureDesc)) {
4141
exit 1
4242
}
4343

44-
# Resolve repository root. Prefer git information when available, but fall back
45-
# to searching for repository markers so the workflow still functions in repositories that
46-
# were initialized with --no-git.
47-
function Find-RepositoryRoot {
48-
param(
49-
[string]$StartDir,
50-
[string[]]$Markers = @('.git', '.specify')
51-
)
52-
$current = Resolve-Path $StartDir
53-
while ($true) {
54-
foreach ($marker in $Markers) {
55-
if (Test-Path (Join-Path $current $marker)) {
56-
return $current
57-
}
58-
}
59-
$parent = Split-Path $current -Parent
60-
if ($parent -eq $current) {
61-
# Reached filesystem root without finding markers
62-
return $null
63-
}
64-
$current = $parent
65-
}
66-
}
67-
6844
function Get-HighestNumberFromSpecs {
6945
param([string]$SpecsDir)
7046

0 commit comments

Comments
 (0)