fix(extensions/git): reject negative -Number in create-new-feature-branch.ps1#3538
Open
Noor-ul-ain001 wants to merge 1 commit into
Open
fix(extensions/git): reject negative -Number in create-new-feature-branch.ps1#3538Noor-ul-ain001 wants to merge 1 commit into
Noor-ul-ain001 wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
create-new-feature-branchscript has three twins (bash, PowerShell, Python). The bash and Python twins validate--numberagainst^[0-9]+$and reject a negative value with:The PowerShell twin declares the parameter as
[long]$Number, so PowerShell binds-5as the integer-5instead of rejecting it. That value then formats via'{0:000}'to-005and 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 lategitfailure instead of the twins' clear, early error.Fix
$Number -lt 0up front (before the empty-description check, matching the bash twin's parse-time validation order) and emit the identical error message.-Number 0is still honored (-lt 0, not-le 0), preserving the fix(git-ext): honor explicit -Number 0 in PowerShell branch creation (parity with bash) #3412 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_honoredpair.Verified manually on Windows PowerShell 5.1:
-Number -5→ exit 1,Error: --number must be a non-negative integer-Number 5→005-...(regression: valid numbers still work)-Number 0→000-...(regression: fix(git-ext): honor explicit -Number 0 in PowerShell branch creation (parity with bash) #3412 behavior preserved)Same PowerShell-parity bug class as #3412 (
-Number 0).🤖 Generated with Claude Code