forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-mirror.ps1
46 lines (33 loc) · 1.03 KB
/
sync-mirror.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<#
.SYNOPSIS
This synchronizes a branch on the current repository to the mirror repo.
.EXAMPLE
sync-mirror.ps1
.EXAMPLE
sync-mirror.ps1 -Branch refs/heads/release/xxxx
#>
param (
[Parameter(Mandatory = $false)]
[string]$Branch = "refs/heads/main"
)
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!"
}
# Remove the 'refs/heads/' prefix.
$BranchName = $Branch.Substring(11)
# Make sure we're in the correct branch.
git checkout $BranchName
# Add the AzDO repo as a remote.
git remote add azdo-mirror "https://nibanks:$Env:[email protected]/msquic/_git/msquic"
# Reset branch to origin.
git reset --hard origin/$BranchName
# Push to the AzDO repo.
try {
git push azdo-mirror $BranchName
} catch {
Write-Host "Supressing exception while running 'git push'"
}
Write-Host "Successfully mirrored latest changes"