fix(scripts): honor explicit -Number 0 in PowerShell create-new-feature (parity with bash)#3196
Conversation
…re (parity with bash)
Get-BranchName used `[long]$Number = 0` as both the default and the 'auto-detect' sentinel (`if ($Number -eq 0)`), so an explicitly-passed `-Number 0` was indistinguishable from 'not supplied' and silently auto-incremented. The bash twin keys off whether the value is non-empty (`[ -z "$BRANCH_NUMBER" ]`), so `--number 0` is honored and yields FEATURE_NUM 000 -- a cross-platform divergence for identical input.
Use $PSBoundParameters.ContainsKey('Number') instead, so an explicit value (including 0) is honored and only a missing -Number auto-detects -- mirroring bash. This also aligns the -Timestamp+-Number warning, which bash emits for `--number 0 --timestamp` (non-empty check) but PowerShell previously skipped.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Note for reviewers: #2036 (open since March, currently conflicting + changes-requested) proposes a broader change to validate |
There was a problem hiding this comment.
Pull request overview
This pull request fixes a cross-platform parity bug in the PowerShell create-new-feature.ps1 script where an explicitly provided -Number 0 was previously indistinguishable from “not supplied,” causing unintended auto-detection. It updates the PowerShell logic to detect whether -Number was actually passed, matching the bash script’s behavior, and adds regression tests to lock in the 0 -> 000-* outcome.
Changes:
- Update PowerShell
create-new-feature.ps1to use$PSBoundParameters.ContainsKey('Number')so an explicit-Number 0is honored and only an omitted-Numbertriggers auto-detect. - Align the
-Timestamp+-Numberwarning behavior so that-Number 0is also treated as “provided” (and therefore warned/ignored), matching bash. - Add bash + PowerShell regression tests validating
--number/-Number 0producesFEATURE_NUM=000andBRANCH_NAME=000-…even when higher-numbered specs exist.
Show a summary per file
| File | Description |
|---|---|
tests/test_timestamp_branches.py |
Adds regression tests pinning the canonical number=0 -> 000-* behavior in bash and ensuring PowerShell matches it. |
scripts/powershell/create-new-feature.ps1 |
Fixes the default-vs-sentinel ambiguity by detecting whether -Number was actually supplied via PSBoundParameters. |
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
|
Thank you! |
Description
create-new-feature.ps1could not honor an explicit-Number 0. The parameter used[long]$Number = 0as both the default and the auto-detect sentinel:So
-Number 0was indistinguishable from not supplied and silently auto-incremented. The bash twin keys off whether the value is non-empty ([ -z "$BRANCH_NUMBER" ]), so--number 0is honored and yieldsFEATURE_NUM=000.Result — identical input, different output across platforms:
--number 0000-feature001-feature(auto)Fix
Use
$PSBoundParameters.ContainsKey('Number')to detect whether-Numberwas actually supplied, so an explicit value (including0) is honored and only a missing-Numberauto-detects — mirroring bash's empty-check. This also aligns the-Timestamp+-Numberwarning, which bash emits for--number 0 --timestamp(non-empty check) but PowerShell previously skipped.Testing
uvx ruff checkclean;tests/test_ps1_encoding.pygreen (edited.ps1stays ASCII / PowerShell 5.1-safe).TestSequentialBranch::test_explicit_number_zero_is_honored(bash) — pins the canonical--number 0->000behavior.TestSequentialBranchPowerShell::test_explicit_number_zero_is_honored_matching_bash— fails before this change (PS auto-detected), passes after.-Number 0->000-zero(even withspecs/003-*present),-Number 5->005-zero, and no-Numberstill auto-detects (004-zerowithspecs/003-*). bash confirmed--number 0->000-zero.AI Disclosure
Found and fixed with Claude Code (Claude Opus 4.8) under my direction. AI located the default-vs-sentinel ambiguity across the bash/PowerShell twins and drafted the
ContainsKeyfix plus regression tests; I reproduced the differingFEATURE_NUMunder Windows PowerShell 5.1 and bash, confirmed auto-detect and explicit non-zero paths are unchanged, and reviewed the diff before submitting.