Skip to content

Commit 7b687d8

Browse files
jawwad-aliclaude
andauthored
fix(scripts): drop HAS_GIT from PowerShell git-extension output (parity with bash) (#3195)
* fix(scripts): drop HAS_GIT from PowerShell git-extension output (parity with bash) create-new-feature-branch.ps1 emitted a HAS_GIT key in its JSON output and a 'HAS_GIT:' line in text output that the bash twin never emits. The bash output contract is {BRANCH_NAME, FEATURE_NUM} (+ DRY_RUN) only, so a tool parsing the machine-readable output got a different shape on Windows/PowerShell vs macOS/Linux -- a cross-platform contract divergence. $hasGit is still computed and used internally for branch-creation logic; only its two output emissions are removed, restoring parity. Added regression tests asserting neither the PS nor the bash output contains HAS_GIT (JSON and text). Noted as a follow-up in #3129. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs: note DRY_RUN in the HAS_GIT-omission comment (parity) Address Copilot review: the comment described the output contract as {BRANCH_NAME, FEATURE_NUM} without mentioning that DRY_RUN is still conditionally added in JSON mode on dry runs. Clarify so the contract description is complete for future maintainers. Comment-only. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7621e1c commit 7b687d8

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

extensions/git/scripts/powershell/create-new-feature-branch.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,17 @@ if ($Json) {
400400
$obj = [PSCustomObject]@{
401401
BRANCH_NAME = $branchName
402402
FEATURE_NUM = $featureNum
403-
HAS_GIT = $hasGit
404403
}
404+
# $hasGit is computed for branch-creation logic only; it is intentionally not
405+
# emitted so this output contract matches the bash twin: BRANCH_NAME and
406+
# FEATURE_NUM, plus DRY_RUN (added just below) on dry runs.
405407
if ($DryRun) {
406408
$obj | Add-Member -NotePropertyName 'DRY_RUN' -NotePropertyValue $true
407409
}
408410
$obj | ConvertTo-Json -Compress
409411
} else {
410412
Write-Output "BRANCH_NAME: $branchName"
411413
Write-Output "FEATURE_NUM: $featureNum"
412-
Write-Output "HAS_GIT: $hasGit"
413414
if (-not $DryRun) {
414415
Write-Output "SPECIFY_FEATURE environment variable set to: $branchName"
415416
}

tests/extensions/git/test_git_extension.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,24 @@ def test_creates_branch_sequential(self, tmp_path: Path):
298298
assert data["BRANCH_NAME"] == "001-user-auth"
299299
assert data["FEATURE_NUM"] == "001"
300300

301+
def test_output_omits_has_git_for_parity(self, tmp_path: Path):
302+
"""The bash output contract is {BRANCH_NAME, FEATURE_NUM} (+ DRY_RUN) in JSON
303+
and a BRANCH_NAME:/FEATURE_NUM: text block -- no HAS_GIT key/line. This pins
304+
the canonical contract the PowerShell twin must mirror."""
305+
project = _setup_project(tmp_path)
306+
rj = _run_bash(
307+
"create-new-feature-branch.sh", project,
308+
"--json", "--dry-run", "--short-name", "parity", "Parity feature",
309+
)
310+
assert rj.returncode == 0, rj.stderr
311+
assert "HAS_GIT" not in json.loads(rj.stdout)
312+
rt = _run_bash(
313+
"create-new-feature-branch.sh", project,
314+
"--dry-run", "--short-name", "parity", "Parity feature",
315+
)
316+
assert rt.returncode == 0, rt.stderr
317+
assert "HAS_GIT" not in rt.stdout
318+
301319
def test_branch_name_short_word_case_sensitivity(self, tmp_path: Path):
302320
"""A short word is dropped from the derived branch name unless it appears
303321
as an acronym in UPPERCASE in the description (case-sensitive, must match the
@@ -444,6 +462,24 @@ def test_creates_branch_sequential(self, tmp_path: Path):
444462
data = json.loads(result.stdout)
445463
assert data["BRANCH_NAME"] == "001-user-auth"
446464

465+
def test_output_omits_has_git_to_match_bash(self, tmp_path: Path):
466+
"""PowerShell must mirror the bash twin's output contract: neither JSON nor
467+
text output may include HAS_GIT (it is computed internally for branch-creation
468+
logic only). Fails before the fix (PS emitted HAS_GIT), passes after."""
469+
project = _setup_project(tmp_path)
470+
rj = _run_pwsh(
471+
"create-new-feature-branch.ps1", project,
472+
"-Json", "-DryRun", "-ShortName", "parity", "Parity feature",
473+
)
474+
assert rj.returncode == 0, rj.stderr
475+
assert "HAS_GIT" not in json.loads(rj.stdout)
476+
rt = _run_pwsh(
477+
"create-new-feature-branch.ps1", project,
478+
"-DryRun", "-ShortName", "parity", "Parity feature",
479+
)
480+
assert rt.returncode == 0, rt.stderr
481+
assert "HAS_GIT" not in rt.stdout
482+
447483
def test_branch_name_short_word_case_sensitivity(self, tmp_path: Path):
448484
"""PowerShell must match the bash twin: a short word is dropped unless it
449485
appears as an acronym in UPPERCASE (case-sensitive -cmatch, not -match)."""

0 commit comments

Comments
 (0)