💫 Toolkit to help you get started with SDD or any other process!
fix(scripts): add empty description validation and branch checkout error handling (#1559)
Zaheer Uddin6757c90dbd03
diff --git a/scripts/bash/create-new-feature.sh b/scripts/bash/create-new-feature.shindex c40cfd77f..54697024d 100644--- a/scripts/bash/create-new-feature.sh+++ b/scripts/bash/create-new-feature.sh@@ -67,6 +67,13 @@ if [ -z "$FEATURE_DESCRIPTION" ]; thenexit 1fi+# Trim whitespace and validate description is not empty (e.g., user passed only whitespace)+FEATURE_DESCRIPTION=$(echo "$FEATURE_DESCRIPTION" | xargs)+if [ -z "$FEATURE_DESCRIPTION" ]; then+ echo "Error: Feature description cannot be empty or contain only whitespace" >&2+ exit 1+fi+# Function to find the repository root by searching for existing project markersfind_repo_root() {local dir="$1"@@ -272,7 +279,16 @@ if [ ${#BRANCH_NAME} -gt $MAX_BRANCH_LENGTH ]; thenfiif [ "$HAS_GIT" = true ]; then- git checkout -b "$BRANCH_NAME"+ if ! git checkout -b "$BRANCH_NAME" 2>/dev/null; then+ # Check if branch already exists+ if git branch --list "$BRANCH_NAME" | grep -q .; then+ >&2 echo "Error: Branch '$BRANCH_NAME' already exists. Please use a different feature name or specify a different number with --number."+ exit 1+ else+ >&2 echo "Error: Failed to create git branch '$BRANCH_NAME'. Please check your git configuration and try again."+ exit 1+ fi+ fielse>&2 echo "[specify] Warning: Git repository not detected; skipped branch creation for $BRANCH_NAME"fidiff --git a/scripts/powershell/create-new-feature.ps1 b/scripts/powershell/create-new-feature.ps1index 2f0172e35..8f88b6c56 100644--- a/scripts/powershell/create-new-feature.ps1+++ b/scripts/powershell/create-new-feature.ps1@@ -35,6 +35,12 @@ if (-not $FeatureDescription -or $FeatureDescription.Count -eq 0) {$featureDesc = ($FeatureDescription -join ' ').Trim()+# Validate description is not empty after trimming (e.g., user passed only whitespace)+if ([string]::IsNullOrWhiteSpace($featureDesc)) {+ Write-Error "Error: Feature description cannot be empty or contain only whitespace"+ exit 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 initialized with --no-git.@@ -242,10 +248,26 @@ if ($branchName.Length -gt $maxBranchLength) {}if ($hasGit) {+ $branchCreated = $falsetry {- git checkout -b $branchName | Out-Null+ git checkout -b $branchName 2>$null | Out-Null+ if ($LASTEXITCODE -eq 0) {+ $branchCreated = $true+ }} catch {- Write-Warning "Failed to create git branch: $branchName"+ # Exception during git command+ }++ if (-not $branchCreated) {+ # Check if branch already exists+ $existingBranch = git branch --list $branchName 2>$null+ if ($existingBranch) {+ Write-Error "Error: Branch '$branchName' already exists. Please use a different feature name or specify a different number with -Number."+ exit 1+ } else {+ Write-Error "Error: Failed to create git branch '$branchName'. Please check your git configuration and try again."+ exit 1+ }}} else {Write-Warning "[specify] Warning: Git repository not detected; skipped branch creation for $branchName"