chore(pwsh): dedup git helpers + drop dead psmux scripts (#129)#131
Conversation
Deferred hygiene items from the 2026-07-17 triage. Verified with Invoke-Pester (578 passing). C2/C3 — extract Get-DotRepoRevision (short SHA + commit date + dirty) into os/45-doctor.ps1 and share it across the doctor's "Repo version" row, the doctor header, and the `core-version` verb (os/48-core.ps1). This also fixes a latent bug: the header re-derived the SHA behind an `if ($root …)` guard whose $root was a local of the OTHER function (Get-DoctorResults), so it was always $null and the header silently printed "dev" instead of the revision. Threading the pre-resolved revision through Get-DoctorResults means one git spawn shared by row + header (was three), and the header now shows the real short SHA. C4 — factor the branch-clean pipeline shared by fbr (core/20-functions.ps1) and tbranch (core/25-television.ps1) into Get-DotGitBranchNames. Dead code — remove psmux/scripts/psmux-cpu.ps1 and psmux-netspeed.ps1; vestigial after the bar was de-pwsh'd, no live #() in psmux.conf (the conf comments already document them as intentionally gone). Also update the load-contract provides/requires headers and Core.Tests.ps1 (stub Get-DotRepoRevision, mirroring the existing Test-Cmd stub, since the front-door test dot-sources 48-core in isolation). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KSeBsL1YesMCpEqxHXSKkv
There was a problem hiding this comment.
Pull request overview
Deduplicates PowerShell git-helper logic by centralizing repo revision resolution and branch-name listing, and removes vestigial psmux status scripts that are no longer referenced—keeping the Windows host layer tidy and consistent across related verbs.
Changes:
- Extract
Get-DotRepoRevisionintopowershell/os/45-doctor.ps1and reuse it indotfiles-doctorandcore-versionto avoid repeatedgitspawning. - Factor branch listing/cleanup into
Get-DotGitBranchNamesand reuse it infbrandtbranch. - Remove dead psmux PowerShell scripts (
psmux-cpu.ps1,psmux-netspeed.ps1) and updateCore.Tests.ps1to stub the new fragment helper.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Core.Tests.ps1 | Stubs Get-DotRepoRevision for isolated dot-sourcing of os/48-core.ps1 in tests. |
| psmux/scripts/psmux-netspeed.ps1 | Deleted vestigial status-segment script. |
| psmux/scripts/psmux-cpu.ps1 | Deleted vestigial status-segment script. |
| powershell/os/48-core.ps1 | Uses shared Get-DotRepoRevision for core-version output and updates load contract header. |
| powershell/os/45-doctor.ps1 | Adds Get-DotRepoRevision and threads resolved revision through results + header to dedup git calls. |
| powershell/core/25-television.ps1 | Switches tbranch to use shared branch-name helper and updates load contract header. |
| powershell/core/20-functions.ps1 | Introduces Get-DotGitBranchNames and updates fbr to use it. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # revision is resolved by the caller and passed in (so the header can reuse the | ||
| # same object without a second git spawn — C2); fall back to resolving it here | ||
| # when called directly with no -RepoRevision. | ||
| $rev = if ($PSBoundParameters.ContainsKey('RepoRevision')) { $RepoRevision } else { Get-DotRepoRevision -Root $root } |
There was a problem hiding this comment.
Fixed in the latest commit. Gate the fallback on $null instead of $PSBoundParameters.ContainsKey, so a caller passing -RepoRevision $null (dotfiles-doctor, on a non-git checkout) re-resolves as documented — correct and cheap, since Get-DotRepoRevision fails fast on the .git check (no git spawn).
Addresses Copilot review: Get-DoctorResults treated `-RepoRevision $null` as "provided" and skipped the documented fallback, making behaviour depend on whether callers pass the parameter at all. Gate the fallback on $null instead — a caller passing $null (dotfiles-doctor, on a non-git checkout) genuinely has no revision, so re-resolving is correct and cheap (Get-DotRepoRevision fails fast on the .git check, no git spawn). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KSeBsL1YesMCpEqxHXSKkv
| Write-DotHost ' re-checking...' -Color Cyan | ||
| $results = Get-DoctorResults | ||
| $results = Get-DoctorResults -RepoRevision $rev | ||
| $s = Get-DoctorSummary $results | ||
| $color = switch ($s.Overall) { 'ok' { 'Green' } 'warn' { 'Yellow' } 'fail' { 'Red' } } |
There was a problem hiding this comment.
Fixed. The -Fix re-check now calls Get-DotRepoRevision -Root $root again before re-running Get-DoctorResults, so the second 'Repo version' row reflects post-fix state. (Today's fix actions all act outside the repo tree — registry, $HOME symlinks, LOCALAPPDATA modules, package installs — so it's defensive, but it keeps the re-check honest.)
Addresses Copilot review: the -Fix re-check reused the pre-fix $rev, so if a fix action touched the working tree the second "Repo version" row could show a stale dirty flag/date. Re-resolve via Get-DotRepoRevision before re-running Get-DoctorResults. Today's fixes all act outside the repo (registry, $HOME symlinks, LOCALAPPDATA modules, package installs), so it's defensive — but it keeps the re-check honest. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KSeBsL1YesMCpEqxHXSKkv
Picks up the dedup cleanups (C2–C4) and dead-code removal from #129. Pure hygiene, low risk. Verified on the Windows host with
Invoke-Pester(578 passing).Changes
C2 / C3 — one shared git-revision resolver. Extracted
Get-DotRepoRevision(short SHA + commit date + dirty flag) intoos/45-doctor.ps1and shared it across three call sites that each open-coded the samegit log/git statusblock: the doctor's "Repo version" row, the doctor report header, and thecore-versionverb (os/48-core.ps1).This also fixes a latent display bug: the header re-derived the SHA behind an
if ($root …)guard, but$rootthere was a local of the other function (Get-DoctorResults), so it was always$null— the header silently printeddotfiles-Windows devinstead of the revision, and thegit rev-parseinside never even ran. Threading the pre-resolved revision throughGet-DoctorResultsmeans the row and header share one git spawn (was three across the two), and the header now shows the real short SHA:C4 — one shared branch lister. Factored the identical branch-clean pipeline in
fbr(core/20-functions.ps1) andtbranch(core/25-television.ps1) intoGet-DotGitBranchNames.Dead code. Removed
psmux/scripts/psmux-cpu.ps1andpsmux/scripts/psmux-netspeed.ps1— vestigial after the psmux bar was de-pwsh'd; no live#()reference inpsmux.conf(its comments already document them as intentionally gone).Verification
core-versionnow all report the same real SHA;Get-DotGitBranchNameslists cleaned refs.provides/requiresheaders updated;Core.Tests.ps1stubsGet-DotRepoRevision(mirroring its existingTest-Cmdstub) since it dot-sources48-corein isolation.Part of #129; the security/packaging tail is a separate follow-up PR.
🤖 Generated with Claude Code