Skip to content

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

Merged
mnriem merged 1 commit into
github:mainfrom
Noor-ul-ain001:fix/ps-negative-number-branch
Jul 15, 2026
Merged

fix(extensions/git): reject negative -Number in create-new-feature-branch.ps1#3538
mnriem merged 1 commit into
github:mainfrom
Noor-ul-ain001:fix/ps-negative-number-branch

Conversation

@Noor-ul-ain001

Copy link
Copy Markdown
Contributor

Summary

The create-new-feature-branch script has three twins (bash, PowerShell, Python). The bash and Python twins validate --number against ^[0-9]+$ and reject a negative value with:

Error: --number must be a non-negative integer

The PowerShell twin declares the parameter as [long]$Number, so PowerShell binds -5 as the integer -5 instead of rejecting it. That value then formats via '{0:000}' to -005 and produces a branch name starting with a dash — e.g. -005-my-feature — which git refuses (refs cannot begin with -). The user gets a confusing late git failure instead of the twins' clear, early error.

Fix

Tests

Added matching negative-number parity tests to both the bash and PowerShell create-feature suites, mirroring the existing test_explicit_number_zero_is_honored pair.

Verified manually on Windows PowerShell 5.1:

Same PowerShell-parity bug class as #3412 (-Number 0).

🤖 Generated with Claude Code

…anch.ps1

The bash and Python twins validate --number against ^[0-9]+$ and reject a
negative value with 'Error: --number must be a non-negative integer'. The
PowerShell twin declares the parameter as [long]$Number, so PowerShell binds
'-5' as -5 instead of rejecting it. That value then formats via '{0:000}' to
'-005' and yields a branch name starting with a dash, which git refuses (refs
cannot begin with '-') — a confusing late failure instead of the twins' clear
early error.

Guard for $Number -lt 0 up front (before the description check, matching the
bash twin's parse-time validation order) and emit the identical error. An
explicit -Number 0 is still honored, preserving the github#3412 fix.

Add matching negative-number parity tests to the bash and PowerShell
create-feature suites, mirroring the existing test_explicit_number_zero_is_honored
pair. Same PowerShell-parity bug class as github#3412.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an input-validation parity gap in the Git extension’s PowerShell create-new-feature-branch script so that negative -Number values are rejected early (matching the bash/Python twins) with the canonical error message, avoiding confusing downstream git failures.

Changes:

  • Add an upfront guard in create-new-feature-branch.ps1 to reject $Number -lt 0 with Error: --number must be a non-negative integer.
  • Add regression tests for negative-number rejection in both the bash and PowerShell create-feature test suites.
Show a summary per file
File Description
tests/extensions/git/test_git_extension.py Adds bash + PowerShell parity tests asserting negative numbers fail with the expected error message.
extensions/git/scripts/powershell/create-new-feature-branch.ps1 Adds early validation to reject negative -Number values before further processing.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Low

@mnriem mnriem merged commit a7f6fe8 into github:main Jul 15, 2026
12 checks passed
@mnriem

mnriem commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants