Skip to content

πŸ’« Toolkit to help you get started with SDD or any other process!

fix(extensions/git): reject negative -Number in create-new-feature-branch.ps1 (#3538)

Noor ul aina7f6fe8dd441
diff --git a/extensions/git/scripts/powershell/create-new-feature-branch.ps1 b/extensions/git/scripts/powershell/create-new-feature-branch.ps1
index 3c47d17e3..1536f9a2b 100644
--- a/extensions/git/scripts/powershell/create-new-feature-branch.ps1
+++ b/extensions/git/scripts/powershell/create-new-feature-branch.ps1
@@ -41,6 +41,16 @@ if ($Help) {
exit 0
}
+# -Number is [long], so PowerShell binds "-5" as -5 rather than rejecting it
+# the way the bash/Python twins do (`^[0-9]+$`). A negative value would format
+# via '{0:000}' to e.g. "-005" and produce a branch name starting with "-",
+# which git refuses (refs cannot begin with a dash). Reject it here, before the
+# description check, matching the bash twin's parse-time validation order.
+if ($Number -lt 0) {
+ Write-Error 'Error: --number must be a non-negative integer'
+ exit 1
+}
+
if (-not $FeatureDescription -or $FeatureDescription.Count -eq 0) {
Write-Error "Usage: ./create-new-feature-branch.ps1 [-Json] [-DryRun] [-AllowExistingBranch] [-ShortName <name>] [-Number N] [-Timestamp] <feature description>"
exit 1
diff --git a/tests/extensions/git/test_git_extension.py b/tests/extensions/git/test_git_extension.py
index 0478b9085..79acfcb79 100644
--- a/tests/extensions/git/test_git_extension.py
+++ b/tests/extensions/git/test_git_extension.py
@@ -653,6 +653,19 @@ class TestCreateFeatureBash:
assert data["BRANCH_NAME"] == "000-zero"
assert data["FEATURE_NUM"] == "000"
+ def test_negative_number_rejected(self, tmp_path: Path):
+ """A negative --number is rejected. Pins the canonical behavior the
+ PowerShell twin must mirror; a negative value would otherwise format to
+ e.g. '-005' and produce a branch name starting with '-', which git
+ refuses (refs cannot begin with a dash)."""
+ project = _setup_project(tmp_path)
+ result = _run_bash(
+ "create-new-feature-branch.sh", project,
+ "--json", "--dry-run", "--number", "-5", "--short-name", "neg", "Negative feature",
+ )
+ assert result.returncode != 0
+ assert "--number must be a non-negative integer" in result.stderr
+
@pytest.mark.skipif(not HAS_PWSH, reason="pwsh not available")
class TestCreateFeaturePowerShell:
@@ -974,6 +987,21 @@ class TestCreateFeaturePowerShell:
assert data["BRANCH_NAME"] == "000-zero"
assert data["FEATURE_NUM"] == "000"
+ def test_negative_number_rejected(self, tmp_path: Path):
+ """A negative -Number is rejected, matching the bash/Python twins'
+ '--number must be a non-negative integer'. Regression guard: -Number is
+ [long], so PowerShell binds '-5' as -5 rather than rejecting it the way
+ the twins' `^[0-9]+$` check does; the value would then format via
+ '{0:000}' to '-005' and yield a branch name starting with '-', which
+ git refuses (refs cannot begin with a dash)."""
+ project = _setup_project(tmp_path)
+ result = _run_pwsh(
+ "create-new-feature-branch.ps1", project,
+ "-Json", "-DryRun", "-Number", "-5", "-ShortName", "neg", "Negative feature",
+ )
+ assert result.returncode != 0
+ assert "--number must be a non-negative integer" in result.stderr
+
# ── auto-commit.sh Tests ─────────────────────────────────────────────────────