mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
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>
This commit is contained in:
@@ -400,8 +400,10 @@ if ($Json) {
|
||||
$obj = [PSCustomObject]@{
|
||||
BRANCH_NAME = $branchName
|
||||
FEATURE_NUM = $featureNum
|
||||
HAS_GIT = $hasGit
|
||||
}
|
||||
# $hasGit is computed for branch-creation logic only; it is intentionally not
|
||||
# emitted so this output contract matches the bash twin: BRANCH_NAME and
|
||||
# FEATURE_NUM, plus DRY_RUN (added just below) on dry runs.
|
||||
if ($DryRun) {
|
||||
$obj | Add-Member -NotePropertyName 'DRY_RUN' -NotePropertyValue $true
|
||||
}
|
||||
@@ -409,7 +411,6 @@ if ($Json) {
|
||||
} else {
|
||||
Write-Output "BRANCH_NAME: $branchName"
|
||||
Write-Output "FEATURE_NUM: $featureNum"
|
||||
Write-Output "HAS_GIT: $hasGit"
|
||||
if (-not $DryRun) {
|
||||
Write-Output "SPECIFY_FEATURE environment variable set to: $branchName"
|
||||
}
|
||||
|
||||
@@ -298,6 +298,24 @@ class TestCreateFeatureBash:
|
||||
assert data["BRANCH_NAME"] == "001-user-auth"
|
||||
assert data["FEATURE_NUM"] == "001"
|
||||
|
||||
def test_output_omits_has_git_for_parity(self, tmp_path: Path):
|
||||
"""The bash output contract is {BRANCH_NAME, FEATURE_NUM} (+ DRY_RUN) in JSON
|
||||
and a BRANCH_NAME:/FEATURE_NUM: text block -- no HAS_GIT key/line. This pins
|
||||
the canonical contract the PowerShell twin must mirror."""
|
||||
project = _setup_project(tmp_path)
|
||||
rj = _run_bash(
|
||||
"create-new-feature-branch.sh", project,
|
||||
"--json", "--dry-run", "--short-name", "parity", "Parity feature",
|
||||
)
|
||||
assert rj.returncode == 0, rj.stderr
|
||||
assert "HAS_GIT" not in json.loads(rj.stdout)
|
||||
rt = _run_bash(
|
||||
"create-new-feature-branch.sh", project,
|
||||
"--dry-run", "--short-name", "parity", "Parity feature",
|
||||
)
|
||||
assert rt.returncode == 0, rt.stderr
|
||||
assert "HAS_GIT" not in rt.stdout
|
||||
|
||||
def test_branch_name_short_word_case_sensitivity(self, tmp_path: Path):
|
||||
"""A short word is dropped from the derived branch name unless it appears
|
||||
as an acronym in UPPERCASE in the description (case-sensitive, must match the
|
||||
@@ -444,6 +462,24 @@ class TestCreateFeaturePowerShell:
|
||||
data = json.loads(result.stdout)
|
||||
assert data["BRANCH_NAME"] == "001-user-auth"
|
||||
|
||||
def test_output_omits_has_git_to_match_bash(self, tmp_path: Path):
|
||||
"""PowerShell must mirror the bash twin's output contract: neither JSON nor
|
||||
text output may include HAS_GIT (it is computed internally for branch-creation
|
||||
logic only). Fails before the fix (PS emitted HAS_GIT), passes after."""
|
||||
project = _setup_project(tmp_path)
|
||||
rj = _run_pwsh(
|
||||
"create-new-feature-branch.ps1", project,
|
||||
"-Json", "-DryRun", "-ShortName", "parity", "Parity feature",
|
||||
)
|
||||
assert rj.returncode == 0, rj.stderr
|
||||
assert "HAS_GIT" not in json.loads(rj.stdout)
|
||||
rt = _run_pwsh(
|
||||
"create-new-feature-branch.ps1", project,
|
||||
"-DryRun", "-ShortName", "parity", "Parity feature",
|
||||
)
|
||||
assert rt.returncode == 0, rt.stderr
|
||||
assert "HAS_GIT" not in rt.stdout
|
||||
|
||||
def test_branch_name_short_word_case_sensitivity(self, tmp_path: Path):
|
||||
"""PowerShell must match the bash twin: a short word is dropped unless it
|
||||
appears as an acronym in UPPERCASE (case-sensitive -cmatch, not -match)."""
|
||||
|
||||
Reference in New Issue
Block a user