File tree Expand file tree Collapse file tree 2 files changed +41
-3
lines changed
Expand file tree Collapse file tree 2 files changed +41
-3
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,13 @@ if [ -z "$FEATURE_DESCRIPTION" ]; then
6767 exit 1
6868fi
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
7178find_repo_root () {
7279 local dir=" $1 "
@@ -272,7 +279,16 @@ if [ ${#BRANCH_NAME} -gt $MAX_BRANCH_LENGTH ]; then
272279fi
273280
274281if [ " $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
276292else
277293 >&2 echo " [specify] Warning: Git repository not detected; skipped branch creation for $BRANCH_NAME "
278294fi
Original file line number Diff line number Diff 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
244250if ($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 "
You can’t perform that action at this time.
0 commit comments