diff --git a/scripts/bash/common.sh b/scripts/bash/common.sh index 6931eccc8..c91f47ecc 100644 --- a/scripts/bash/common.sh +++ b/scripts/bash/common.sh @@ -1,8 +1,19 @@ #!/usr/bin/env bash # Common functions and variables for all scripts -# Get repository root, with fallback for non-git repositories +# Get repository root, prioritizing .specify over .git, with fallback for non-git repositories get_repo_root() { + # First check for .specify directory (highest priority) + local current_dir="$(pwd)" + while [ "$current_dir" != "/" ]; do + if [ -d "$current_dir/.specify" ]; then + echo "$current_dir" + return 0 + fi + current_dir="$(dirname "$current_dir")" + done + + # Then check git if available if git rev-parse --show-toplevel >/dev/null 2>&1; then git rev-parse --show-toplevel else diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.sh index 510f62046..1c47f5f72 100644 --- a/scripts/bash/create-new-feature.sh +++ b/scripts/bash/create-new-feature.sh @@ -59,21 +59,22 @@ find_repo_root() { return 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 initialised with --no-git. +# Resolve repository root. Prioritize .specify directory over git information +# to ensure specs/ is created in the correct location for multiproject setups. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -if git rev-parse --show-toplevel >/dev/null 2>&1; then - REPO_ROOT=$(git rev-parse --show-toplevel) - HAS_GIT=true -else - 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 +# First try to find .specify directory (highest priority) +REPO_ROOT="$(find_repo_root "$SCRIPT_DIR")" +if [ -n "$REPO_ROOT" ]; then + # Check if this is a git repository + if git rev-parse --show-toplevel >/dev/null 2>&1; then + HAS_GIT=true + else + HAS_GIT=false fi - HAS_GIT=false +else + echo "Error: Could not determine repository root. Please run this script from within the repository." >&2 + exit 1 fi cd "$REPO_ROOT" diff --git a/scripts/powershell/common.ps1 b/scripts/powershell/common.ps1 index b0be27354..dd1dfd652 100644 --- a/scripts/powershell/common.ps1 +++ b/scripts/powershell/common.ps1 @@ -2,6 +2,17 @@ # Common PowerShell functions analogous to common.sh function Get-RepoRoot { + # First check for .specify directory (highest priority) + $currentDir = Get-Location + while ($currentDir.Path -ne $currentDir.Drive.Root) { + $specifyPath = Join-Path $currentDir ".specify" + if (Test-Path $specifyPath -PathType Container) { + return $currentDir.Path + } + $currentDir = $currentDir.Parent + } + + # Then check git if available try { $result = git rev-parse --show-toplevel 2>$null if ($LASTEXITCODE -eq 0) {