Skip to content

Commit 8c0107a

Browse files
committed
fix: Add proper error handling for git ls-remote commands
- Check $LASTEXITCODE after git ls-remote calls - Prevent parsing error messages as commit hashes - Fixes potential corruption of CMake files with 'fatal:' etc. - Applies to both Update-CMakeFile and Find-TagForHash functions Fixes critical bug where network failures could corrupt dependency files.
1 parent b9c8c4f commit 8c0107a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

updater/scripts/cmake-functions.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ function Parse-CMakeFetchContent($filePath, $depName) {
4040
function Find-TagForHash($repo, $hash) {
4141
try {
4242
$refs = git ls-remote --tags $repo
43+
if ($LASTEXITCODE -ne 0) {
44+
throw "Failed to fetch tags from repository $repo (git ls-remote failed with exit code $LASTEXITCODE)"
45+
}
4346
foreach ($ref in $refs) {
4447
$commit, $tagRef = $ref -split '\s+', 2
4548
if ($commit -eq $hash) {
@@ -99,6 +102,9 @@ function Update-CMakeFile($filePath, $depName, $newValue) {
99102
if ($wasHash) {
100103
# Convert tag to hash and add comment
101104
$newHashRefs = git ls-remote $repo "refs/tags/$newValue"
105+
if ($LASTEXITCODE -ne 0) {
106+
throw "Failed to fetch tag $newValue from repository $repo (git ls-remote failed with exit code $LASTEXITCODE)"
107+
}
102108
if (-not $newHashRefs) {
103109
throw "Tag $newValue not found in repository $repo"
104110
}

0 commit comments

Comments
 (0)