Skip to content

Commit 3c57223

Browse files
committed
Use cwd for repo root if .specify is present
1 parent e6d6f3c commit 3c57223

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

‎scripts/bash/common.sh‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
# Get repository root, with fallback for non-git repositories
55
get_repo_root() {
6-
if git rev-parse --show-toplevel >/dev/null 2>&1; then
6+
# Check if current working directory has .specify folder first
7+
if [ -d "$PWD/.specify" ]; then
8+
echo "$PWD"
9+
elif git rev-parse --show-toplevel >/dev/null 2>&1; then
710
git rev-parse --show-toplevel
811
else
912
# Fall back to script location for non-git repos

‎scripts/bash/create-new-feature.sh‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ check_existing_branches() {
116116
# were initialised with --no-git.
117117
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
118118

119-
if git rev-parse --show-toplevel >/dev/null 2>&1; then
119+
# Check if current working directory has .specify folder first
120+
if [ -d "$PWD/.specify" ]; then
121+
REPO_ROOT="$PWD"
122+
if git rev-parse --show-toplevel >/dev/null 2>&1; then
123+
HAS_GIT=true
124+
else
125+
HAS_GIT=false
126+
fi
127+
elif git rev-parse --show-toplevel >/dev/null 2>&1; then
120128
REPO_ROOT=$(git rev-parse --show-toplevel)
121129
HAS_GIT=true
122130
else

‎scripts/powershell/common.ps1‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# Common PowerShell functions analogous to common.sh
33

44
function Get-RepoRoot {
5+
# Check if current working directory has .specify folder first
6+
if (Test-Path (Join-Path $PWD '.specify')) {
7+
return $PWD
8+
}
9+
510
try {
611
$result = git rev-parse --show-toplevel 2>$null
712
if ($LASTEXITCODE -eq 0) {
@@ -10,7 +15,7 @@ function Get-RepoRoot {
1015
} catch {
1116
# Git command failed
1217
}
13-
18+
1419
# Fall back to script location for non-git repos
1520
return (Resolve-Path (Join-Path $PSScriptRoot "../../..")).Path
1621
}

‎scripts/powershell/create-new-feature.ps1‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,27 @@ if (-not $fallbackRoot) {
133133
exit 1
134134
}
135135

136-
try {
137-
$repoRoot = git rev-parse --show-toplevel 2>$null
138-
if ($LASTEXITCODE -eq 0) {
139-
$hasGit = $true
140-
} else {
141-
throw "Git not available"
136+
# Check if current working directory has .specify folder first
137+
if (Test-Path (Join-Path $PWD '.specify')) {
138+
$repoRoot = $PWD
139+
try {
140+
git rev-parse --show-toplevel 2>$null | Out-Null
141+
$hasGit = ($LASTEXITCODE -eq 0)
142+
} catch {
143+
$hasGit = $false
144+
}
145+
} else {
146+
try {
147+
$repoRoot = git rev-parse --show-toplevel 2>$null
148+
if ($LASTEXITCODE -eq 0) {
149+
$hasGit = $true
150+
} else {
151+
throw "Git not available"
152+
}
153+
} catch {
154+
$repoRoot = $fallbackRoot
155+
$hasGit = $false
142156
}
143-
} catch {
144-
$repoRoot = $fallbackRoot
145-
$hasGit = $false
146157
}
147158

148159
Set-Location $repoRoot

0 commit comments

Comments
 (0)