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
18 changes: 17 additions & 1 deletion scripts/bash/create-new-feature.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ if [ -z "$FEATURE_DESCRIPTION" ]; then
exit 1
fi

# 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 markers
find_repo_root() {
local dir="$1"
Expand Down Expand Up @@ -272,7 +279,16 @@ if [ ${#BRANCH_NAME} -gt $MAX_BRANCH_LENGTH ]; then
fi

if [ "$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
fi
else
>&2 echo "[specify] Warning: Git repository not detected; skipped branch creation for $BRANCH_NAME"
fi
Expand Down
26 changes: 24 additions & 2 deletions scripts/powershell/create-new-feature.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -242,10 +248,26 @@ if ($branchName.Length -gt $maxBranchLength) {
}

if ($hasGit) {
$branchCreated = $false
try {
git checkout -b $branchName | Out-Null
git checkout -b $branchName 2>&1 | Out-Null
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

The stderr redirection 2>&1 is inconsistent with other git commands in this file, which use 2>$null. For consistency and to match the pattern used elsewhere (lines 88, 115, 145, 263), this should be 2>$null | Out-Null instead of 2>&1 | Out-Null.

Suggested change
git checkout -b $branchName 2>&1 | Out-Null
git checkout -b $branchName 2>$null | Out-Null

Copilot uses AI. Check for mistakes.
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"
Expand Down