-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Use workdir as root for everything instead of repo root #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,8 @@ | ||
| #!/usr/bin/env bash | ||
| # Common functions and variables for all scripts | ||
|
|
||
| # Get repository root, with fallback for non-git repositories | ||
| get_repo_root() { | ||
| 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="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| (cd "$script_dir/../../.." && pwd) | ||
| fi | ||
| } | ||
| # Set working directory | ||
| WORKING_DIR="$(pwd)" | ||
|
|
||
| # Get current branch, with fallback for non-git repositories | ||
| get_current_branch() { | ||
|
|
@@ -27,8 +19,7 @@ get_current_branch() { | |
| fi | ||
|
|
||
| # For non-git repos, try to find the latest feature directory | ||
| local repo_root=$(get_repo_root) | ||
| local specs_dir="$repo_root/specs" | ||
| local specs_dir="$WORKING_DIR/specs" | ||
|
|
||
| if [[ -d "$specs_dir" ]]; then | ||
| local latest_feature="" | ||
|
|
@@ -81,21 +72,20 @@ check_feature_branch() { | |
| return 0 | ||
| } | ||
|
|
||
| get_feature_dir() { echo "$1/specs/$2"; } | ||
| get_feature_dir() { echo "$WORKING_DIR/specs/$1"; } | ||
|
||
|
|
||
| get_feature_paths() { | ||
| local repo_root=$(get_repo_root) | ||
| local current_branch=$(get_current_branch) | ||
| local has_git_repo="false" | ||
|
|
||
| if has_git; then | ||
| has_git_repo="true" | ||
| fi | ||
|
|
||
| local feature_dir=$(get_feature_dir "$repo_root" "$current_branch") | ||
| local feature_dir=$(get_feature_dir "$current_branch") | ||
|
|
||
| cat <<EOF | ||
| REPO_ROOT='$repo_root' | ||
| WORKING_DIR='$WORKING_DIR' | ||
| CURRENT_BRANCH='$current_branch' | ||
| HAS_GIT='$has_git_repo' | ||
| FEATURE_DIR='$feature_dir' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -31,26 +31,18 @@ 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. | ||||
| # Set working directory | ||||
|
Comment on lines
31
to
+34
|
||||
| WORKING_DIR="$(pwd)" | ||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||
|
|
||||
| # Check git availability | ||||
| 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 | ||||
| fi | ||||
| HAS_GIT=false | ||||
| fi | ||||
|
|
||||
| cd "$REPO_ROOT" | ||||
|
|
||||
| SPECS_DIR="$REPO_ROOT/specs" | ||||
| SPECS_DIR="$WORKING_DIR/specs" | ||||
| mkdir -p "$SPECS_DIR" | ||||
|
|
||||
| HIGHEST=0 | ||||
|
|
@@ -80,7 +72,8 @@ fi | |||
| FEATURE_DIR="$SPECS_DIR/$BRANCH_NAME" | ||||
| mkdir -p "$FEATURE_DIR" | ||||
|
|
||||
| TEMPLATE="$REPO_ROOT/.specify/templates/spec-template.md" | ||||
| TEMPLATE="$WORKING_DIR/.specify/templates/spec-template.md" | ||||
|
|
||||
|
||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,50 +14,22 @@ if (-not $FeatureDescription -or $FeatureDescription.Count -eq 0) { | |||||
| } | ||||||
| $featureDesc = ($FeatureDescription -join ' ').Trim() | ||||||
|
|
||||||
| # 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. | ||||||
| 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 | ||||||
| } | ||||||
| } | ||||||
| $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 | ||||||
| } | ||||||
| # Set working directory | ||||||
| $workingDir = Get-Location | ||||||
|
Comment on lines
+17
to
+18
|
||||||
|
|
||||||
| # Check git availability | ||||||
| try { | ||||||
| $repoRoot = git rev-parse --show-toplevel 2>$null | ||||||
| git rev-parse --show-toplevel 2>$null | Out-Null | ||||||
|
||||||
| git rev-parse --show-toplevel 2>$null | Out-Null | |
| git rev-parse --show-toplevel >$null 2>&1 |
Uh oh!
There was an error while loading. Please reload this page.