Skip to content

Commit 5ed1b18

Browse files
committed
Fixed case when remote default branch cannot be fetched (empty repo)
1 parent 424d573 commit 5ed1b18

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

sync.ps1

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function Get-DefaultBranch {
3333
[string]$Url
3434
)
3535
$output = git ls-remote --symref $Url HEAD
36-
[BranchInfo]::new($shaPattern.Match($output).Value, $branchPattern.Match($output).Value)
36+
if ($output) {
37+
[BranchInfo]::new($shaPattern.Match($output).Value, $branchPattern.Match($output).Value)
38+
}
3739
}
3840

3941
function Get-OutdatedRemotes {
@@ -53,18 +55,23 @@ function Get-OutdatedRemotes {
5355
Write-Host "`t$remoteName " -ForegroundColor Cyan -NoNewline
5456
$branchRemote = Get-DefaultBranch $remoteUrl
5557

56-
if ($branchRemote.SHA -eq $masterBranch.SHA) {
57-
Write-Host "[OK]" -ForegroundColor Green
58+
if ($branchRemote) {
59+
if ($branchRemote.SHA -eq $masterBranch.SHA) {
60+
Write-Host "[OK]" -ForegroundColor Green
61+
}
62+
else {
63+
Write-Host "[MISSMATCH]" -ForegroundColor Red
64+
Write-Host "Master SHA: $($masterBranch.SHA)" -ForegroundColor Yellow
65+
Write-Host "Remote SHA: $($branchRemote.SHA)" -ForegroundColor Yellow
66+
$_
67+
}
5868
}
5969
else {
60-
Write-Host "[MISSMATCH]" -ForegroundColor Red
61-
Write-Host "Master SHA: $($masterBranch.SHA)" -ForegroundColor Yellow
62-
Write-Host "Remote SHA: $($branchRemote.SHA)" -ForegroundColor Yellow
70+
Write-Host "[MISSING]" -ForegroundColor Red
71+
write-host "Default branch not found" -ForegroundColor Yellow
6372
$_
6473
}
6574
}
66-
67-
6875
}
6976

7077
Clear-Host

0 commit comments

Comments
 (0)