Skip to content

Commit 1823f19

Browse files
Copilotshanselman
andauthored
Preflight GitVersion repository history before build (#896)
* Initial plan * Improve GitVersion repository prerequisite checks Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: shanselman <2892+shanselman@users.noreply.github.com>
1 parent 0b8ba41 commit 1823f19

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

build.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,24 @@ function Ensure-GitVersionRepositoryTrust {
138138
Write-Success "Repository trusted for GitVersion"
139139
}
140140

141+
function Ensure-GitVersionRepositoryHistory {
142+
$insideWorkTree = & git -C $repoRoot rev-parse --is-inside-work-tree 2>$null
143+
if ($LASTEXITCODE -ne 0 -or $insideWorkTree -ne "true") {
144+
Write-Error "Git metadata not found. GitVersion requires a git clone with full history."
145+
Write-Info "Clone the repository with git, then rerun .\build.ps1."
146+
$script:issues += "Repository is missing git metadata required by GitVersion"
147+
return
148+
}
149+
150+
$isShallow = & git -C $repoRoot rev-parse --is-shallow-repository 2>$null
151+
if ($LASTEXITCODE -eq 0 -and $isShallow -eq "true") {
152+
Write-Error "Repository is a shallow clone. GitVersion requires full git history."
153+
Write-Info "Run this once, then retry the build:"
154+
Write-Info "git fetch --unshallow --tags origin"
155+
$script:issues += "Repository is shallow; GitVersion requires full history"
156+
}
157+
}
158+
141159
Write-Host @"
142160
143161
🦞 OpenClaw Windows Hub - Build Script
@@ -200,6 +218,7 @@ if (-not $git) {
200218
}
201219

202220
Ensure-GitVersionRepositoryTrust
221+
Ensure-GitVersionRepositoryHistory
203222
}
204223

205224
# Check Node.js + npm (WinUI build runs `npm ci` to restore @microsoft/mxc-sdk

tests/OpenClaw.Tray.Tests/VersioningContractTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ public void GitVersion_MainBranchPreservesAlphaReleaseTags()
5555
mainBranchMatch.Groups["body"].Value);
5656
}
5757

58+
[Fact]
59+
public void BuildScript_PreflightsGitVersionRepositoryHistory()
60+
{
61+
var repoRoot = TestRepositoryPaths.GetRepositoryRoot();
62+
var buildScript = File.ReadAllText(Path.Combine(repoRoot, "build.ps1"));
63+
64+
Assert.Contains("Git metadata not found. GitVersion requires a git clone with full history.", buildScript);
65+
Assert.Contains("rev-parse --is-shallow-repository", buildScript);
66+
Assert.Contains("GitVersion requires full git history", buildScript);
67+
Assert.Contains("git fetch --unshallow --tags origin", buildScript);
68+
}
69+
5870
[Fact]
5971
public void ActiveCodeAndTests_DoNotContainStaleReleaseVersion()
6072
{

0 commit comments

Comments
 (0)