Skip to content

Commit 6757c90

Browse files
zaheer15351Augment Agent
andauthored
fix(scripts): add empty description validation and branch checkout error handling (#1559)
* fix(scripts): add empty description validation and branch checkout error handling Adds two critical improvements to both PowerShell and Bash feature creation scripts: 1. Post-trim validation: Prevents creating features with whitespace-only descriptions 2. Branch checkout error handling: Provides clear error messages when branch creation fails (e.g., branch already exists) instead of silently continuing Co-authored-by: Augment Agent <noreply@augmentcode.com> * fix(scripts): use consistent stderr redirection for branch checkout --------- Co-authored-by: Augment Agent <noreply@augmentcode.com>
1 parent f6264d4 commit 6757c90

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

scripts/bash/create-new-feature.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ if [ -z "$FEATURE_DESCRIPTION" ]; then
6767
exit 1
6868
fi
6969

70+
# Trim whitespace and validate description is not empty (e.g., user passed only whitespace)
71+
FEATURE_DESCRIPTION=$(echo "$FEATURE_DESCRIPTION" | xargs)
72+
if [ -z "$FEATURE_DESCRIPTION" ]; then
73+
echo "Error: Feature description cannot be empty or contain only whitespace" >&2
74+
exit 1
75+
fi
76+
7077
# Function to find the repository root by searching for existing project markers
7178
find_repo_root() {
7279
local dir="$1"
@@ -272,7 +279,16 @@ if [ ${#BRANCH_NAME} -gt $MAX_BRANCH_LENGTH ]; then
272279
fi
273280

274281
if [ "$HAS_GIT" = true ]; then
275-
git checkout -b "$BRANCH_NAME"
282+
if ! git checkout -b "$BRANCH_NAME" 2>/dev/null; then
283+
# Check if branch already exists
284+
if git branch --list "$BRANCH_NAME" | grep -q .; then
285+
>&2 echo "Error: Branch '$BRANCH_NAME' already exists. Please use a different feature name or specify a different number with --number."
286+
exit 1
287+
else
288+
>&2 echo "Error: Failed to create git branch '$BRANCH_NAME'. Please check your git configuration and try again."
289+
exit 1
290+
fi
291+
fi
276292
else
277293
>&2 echo "[specify] Warning: Git repository not detected; skipped branch creation for $BRANCH_NAME"
278294
fi

scripts/powershell/create-new-feature.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ if (-not $FeatureDescription -or $FeatureDescription.Count -eq 0) {
3535

3636
$featureDesc = ($FeatureDescription -join ' ').Trim()
3737

38+
# Validate description is not empty after trimming (e.g., user passed only whitespace)
39+
if ([string]::IsNullOrWhiteSpace($featureDesc)) {
40+
Write-Error "Error: Feature description cannot be empty or contain only whitespace"
41+
exit 1
42+
}
43+
3844
# Resolve repository root. Prefer git information when available, but fall back
3945
# to searching for repository markers so the workflow still functions in repositories that
4046
# were initialized with --no-git.
@@ -242,10 +248,26 @@ if ($branchName.Length -gt $maxBranchLength) {
242248
}
243249

244250
if ($hasGit) {
251+
$branchCreated = $false
245252
try {
246-
git checkout -b $branchName | Out-Null
253+
git checkout -b $branchName 2>$null | Out-Null
254+
if ($LASTEXITCODE -eq 0) {
255+
$branchCreated = $true
256+
}
247257
} catch {
248-
Write-Warning "Failed to create git branch: $branchName"
258+
# Exception during git command
259+
}
260+
261+
if (-not $branchCreated) {
262+
# Check if branch already exists
263+
$existingBranch = git branch --list $branchName 2>$null
264+
if ($existingBranch) {
265+
Write-Error "Error: Branch '$branchName' already exists. Please use a different feature name or specify a different number with -Number."
266+
exit 1
267+
} else {
268+
Write-Error "Error: Failed to create git branch '$branchName'. Please check your git configuration and try again."
269+
exit 1
270+
}
249271
}
250272
} else {
251273
Write-Warning "[specify] Warning: Git repository not detected; skipped branch creation for $branchName"

0 commit comments

Comments
 (0)