Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion scripts/bash/common.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
25 changes: 13 additions & 12 deletions scripts/bash/create-new-feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +66 to 78
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
# Source common functions
source "$SCRIPT_DIR/common.sh"
# Get all paths and variables from common functions
eval $(get_feature_paths)

If you have already fixed the get_repo_root method, why not use it ?


cd "$REPO_ROOT"
Expand Down
11 changes: 11 additions & 0 deletions scripts/powershell/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down