2020-05-13 05:08:05 +03:00
|
|
|
<#
|
|
|
|
|
|
|
|
.SYNOPSIS
|
2021-11-08 19:45:13 +03:00
|
|
|
This synchronizes a branch or tag on the current repository to the mirror repo.
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
sync-mirror.ps1
|
|
|
|
|
|
|
|
.EXAMPLE
|
2021-11-08 19:45:13 +03:00
|
|
|
sync-mirror.ps1 -Source refs/heads/release/1.0.0
|
|
|
|
|
|
|
|
.EXAMPLE
|
|
|
|
sync-mirror.ps1 -Source refs/tags/v1.0.0
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory = $false)]
|
2021-11-08 19:45:13 +03:00
|
|
|
[string]$Source = "refs/heads/main"
|
2020-05-13 05:08:05 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
Set-StrictMode -Version 'Latest'
|
|
|
|
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
|
|
|
|
|
|
|
|
# Verify the PAT environmental variable is set.
|
|
|
|
if ($null -eq $Env:AzDO_PAT -or "" -eq $Env:AzDO_PAT) {
|
|
|
|
Write-Error "PAT for Azure DevOps Repo doesn't exist!"
|
|
|
|
}
|
|
|
|
|
2021-11-08 20:04:58 +03:00
|
|
|
# Add the AzDO repo as a remote.
|
|
|
|
git remote add azdo-mirror "https://nibanks:$Env:AzDO_PAT@mscodehub.visualstudio.com/msquic/_git/msquic"
|
|
|
|
|
2021-11-08 19:45:13 +03:00
|
|
|
$SourceName = "" # The name of the branch or tag
|
|
|
|
|
|
|
|
if ($Source.StartsWith("refs/heads/")) {
|
|
|
|
|
|
|
|
# Remove the 'refs/heads/' prefix.
|
|
|
|
$SourceName = $Source.Substring(11)
|
|
|
|
|
|
|
|
# Make sure we're in the correct branch.
|
|
|
|
git checkout $SourceName
|
|
|
|
|
|
|
|
# Reset branch to origin.
|
|
|
|
git reset --hard origin/$SourceName
|
2020-05-13 05:08:05 +03:00
|
|
|
|
2021-11-08 19:52:34 +03:00
|
|
|
} elseif ($Source.StartsWith("refs/tags/")) {
|
2021-11-08 19:45:13 +03:00
|
|
|
|
|
|
|
# Remove the 'refs/tags/' prefix.
|
|
|
|
$SourceName = $Source.Substring(10)
|
|
|
|
|
|
|
|
# Make sure we're in the correct tag.
|
|
|
|
git checkout $SourceName
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Write-Error "Unsupported source: " + $Source
|
|
|
|
}
|
2020-05-13 05:08:05 +03:00
|
|
|
|
2021-11-08 20:04:58 +03:00
|
|
|
# Some extra info for debugging failures.
|
|
|
|
git log -5
|
|
|
|
git status
|
2020-05-13 05:08:05 +03:00
|
|
|
|
|
|
|
# Push to the AzDO repo.
|
|
|
|
try {
|
2021-11-08 19:45:13 +03:00
|
|
|
git push azdo-mirror $SourceName
|
2020-05-13 05:08:05 +03:00
|
|
|
} catch {
|
|
|
|
Write-Host "Supressing exception while running 'git push'"
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Successfully mirrored latest changes"
|