fix(desktop): stop hard-failing pack on non-git checkouts + fix ZIP-path autocrlf (supersedes #67643) (#67730)

* fix(desktop): allow write-build-stamp from non-git checkouts

Stop hard-failing npm pack when neither GITHUB_SHA nor git HEAD is
available (ZIP installs / broken .git). Emit an explicit fallback stamp
instead so local Windows desktop builds can finish (#50823).

* fix(desktop): treat fallback stamps as unpinned; harden Windows install

Keep all-zero fallback commits out of -Commit/--commit pins and fetch
install.ps1 by branch instead. After bootstrap, pin the marker to the
checkout HEAD so isBootstrapComplete accepts it. On Windows, force ZIP
checkout, seed GITHUB_SHA (ASCII-only install.ps1), and avoid the pack
stamp failure.

* fix(install): pin core.autocrlf=false before ZIP-path checkout (#50823 review)

The ZIP-fallback path added in #67643 runs `git checkout -f FETCH_HEAD`
before core.autocrlf gets pinned (which only happened later, on the
shared clone-path config). On Git for Windows -- where core.autocrlf
defaults to true -- that renormalizes the repo's LF text files to CRLF in
the working tree during checkout, leaving the freshly-created managed
checkout dirty versus HEAD and aborting the next `hermes update`. That is
the exact "dirty tree the user never touched" failure the surrounding
code already guards against (install.ps1:1461-1469, 1750-1753).

Move the `config core.autocrlf false` pin to run immediately after
`git init`, before the fetch/checkout. The later idempotent pin on the
shared clone path is retained so git-clone installs are unaffected.

Addresses teknium1's review on #67643 and supersedes it, preserving the
original author's two commits.

Co-authored-by: HexLab98 <8422520+HexLab98@users.noreply.github.com>

* chore(contributors): map austinpickett commit email for attribution

The check-attribution CI gate flagged austinpickett@users.noreply.github.com
as an unmapped commit-author email (introduced by the autocrlf fix commit
on this PR). Add the per-email mapping file as the gate instructs (the
legacy AUTHOR_MAP in scripts/release.py is frozen).

---------

Co-authored-by: HexLab98 <liruixinch@outlook.com>
Co-authored-by: austinpickett <austinpickett@users.noreply.github.com>
Co-authored-by: HexLab98 <8422520+HexLab98@users.noreply.github.com>
This commit is contained in:
Austin Pickett 2026-07-19 19:29:36 -04:00 committed by GitHub
parent 8142331616
commit bc6839aa37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 478 additions and 36 deletions

View file

@ -1686,11 +1686,54 @@ function Install-Repository {
Move-Item $extractedDir.FullName $InstallDir -Force
Write-Success "Downloaded and extracted"
# Initialize git repo so updates work later
# Initialize git repo so updates work later. A bare
# `git init` leaves NO HEAD -- desktop's write-build-stamp
# then hard-fails with "could not determine git commit"
# (#50823 / #61657). Fetch the requested ref and force-check
# it out (-f) so untracked ZIP files cannot block checkout.
Push-Location $InstallDir
git -c windows.appendAtomically=false init 2>$null
git -c windows.appendAtomically=false config windows.appendAtomically false 2>$null
# Pin autocrlf=false BEFORE the checkout below. Git for Windows
# defaults to core.autocrlf=true, which would renormalize the
# repo's LF text files to CRLF in the working tree during
# `checkout -f FETCH_HEAD` -- leaving this freshly-created
# managed checkout dirty vs HEAD and aborting the next
# `hermes update` (see the notes at the shared clone-path
# config below and install.ps1:1461-1469). The later pin on
# the shared path is idempotent and still covers git clones.
git -c windows.appendAtomically=false config core.autocrlf false 2>$null
git remote add origin $RepoUrlHttps 2>$null
$fetchRef = if ($Commit) { $Commit } elseif ($Tag) { "refs/tags/$Tag" } else { $Branch }
Write-Info "Fetching $fetchRef so the ZIP checkout has a resolvable HEAD..."
$prevZipEAP = $ErrorActionPreference
$ErrorActionPreference = "Continue"
try {
git -c windows.appendAtomically=false fetch --depth 1 origin $fetchRef 2>&1 | Out-Null
if ($LASTEXITCODE -eq 0) {
if ($Commit -or $Tag) {
git -c windows.appendAtomically=false checkout -f --detach FETCH_HEAD 2>&1 | Out-Null
} else {
git -c windows.appendAtomically=false checkout -f -B $Branch FETCH_HEAD 2>&1 | Out-Null
}
if ($LASTEXITCODE -eq 0) {
Write-Success "ZIP checkout pinned to $fetchRef"
} else {
# Checkout blocked, but FETCH_HEAD still has a SHA we can stamp with.
$fetchSha = & git -c windows.appendAtomically=false rev-parse FETCH_HEAD 2>$null
if ($LASTEXITCODE -eq 0 -and $fetchSha) {
if (-not $env:GITHUB_SHA) { $env:GITHUB_SHA = ("$fetchSha").Trim() }
Write-Warn "ZIP checkout failed; seeded GITHUB_SHA from FETCH_HEAD for desktop stamp"
} else {
Write-Warn "ZIP extract succeeded but git checkout failed -- desktop build may need `$env:GITHUB_SHA"
}
}
} else {
Write-Warn "ZIP extract succeeded but git fetch of $fetchRef failed -- desktop build may need `$env:GITHUB_SHA"
}
} finally {
$ErrorActionPreference = $prevZipEAP
}
Pop-Location
Write-Success "Git repo initialized for future updates"
@ -2888,6 +2931,41 @@ function Install-Desktop {
# for some other tool, electron-builder would still try to sign.
Write-Info "Building desktop app (this takes 1-3 minutes)..."
$buildLog = "$env:TEMP\hermes-desktop-build-$(Get-Random).log"
# Seed GITHUB_SHA for write-build-stamp.mjs. The stamp prefers CI env vars
# over `git rev-parse`, so this covers: (1) node can't find git.exe on PATH
# even though this PowerShell session can, (2) ZIP/init trees that still
# lack a HEAD after a failed post-extract fetch. Without it the desktop
# pack dies with "could not determine git commit" (#50823).
if (-not $env:GITHUB_SHA) {
if ($Commit) {
$env:GITHUB_SHA = $Commit
} else {
Push-Location $InstallDir
try {
$global:LASTEXITCODE = 0
$resolvedSha = & git -c windows.appendAtomically=false rev-parse HEAD 2>$null
if ($LASTEXITCODE -ne 0 -or -not $resolvedSha) {
# ZIP path may have FETCH_HEAD after a fetch even when HEAD is unset.
$global:LASTEXITCODE = 0
$resolvedSha = & git -c windows.appendAtomically=false rev-parse FETCH_HEAD 2>$null
}
if ($LASTEXITCODE -eq 0 -and $resolvedSha) {
$env:GITHUB_SHA = ("$resolvedSha").Trim()
}
} catch { } finally {
Pop-Location
}
}
}
if (-not $env:GITHUB_REF_NAME) {
$env:GITHUB_REF_NAME = if ($Branch) { $Branch } else { "main" }
}
if ($env:GITHUB_SHA) {
$shaPreview = if ($env:GITHUB_SHA.Length -ge 12) { $env:GITHUB_SHA.Substring(0, 12) } else { $env:GITHUB_SHA }
Write-Info "Desktop build stamp: $shaPreview ($($env:GITHUB_REF_NAME))"
} else {
Write-Warn "Could not resolve a git commit for the desktop stamp -- write-build-stamp will use its non-git fallback"
}
Push-Location $desktopDir
$prevEAP = $ErrorActionPreference
$prevCSCAuto = $env:CSC_IDENTITY_AUTO_DISCOVERY