- # Helper to check the error level of the latest command (exit with error when appropriate)
- function c() { if (!$?) { exit(1) } }
-
- # Add build agent's MinGit to PATH
- $env:PATH = $env:AGENT_HOMEDIRECTORY +"\externals\\git\cmd;" +$env:PATH
-
- # Helper to initialize (or update) a Git worktree
- function init ($path, $url, $set_origin) {
- if (Test-Path $path) {
- cd $path; c
- if (Test-Path .git) {
- & git init; c
- } else {
- & git status
- }
- } else {
- & git init $path; c
- cd $path; c
- }
- & git config core.autocrlf false; c
- & git config core.untrackedCache true; c
- if (($set_origin -ne 0) -and !(git config remote.origin.url)) {
- & git remote add origin $url; c
- }
- & git fetch --depth=1 $url master; c
- & git reset --hard FETCH_HEAD; c
- & git clean -df; c
- }
-
- # Initialize Git for Windows' SDK
- $sdk_path = "$(Build.SourcesDirectory)\git-sdk-64"
- init "$sdk_path" "https://dev.azure.com/git-for-windows/git-sdk-64/_git/git-sdk-64" 0
+ $urlbase = "https://dev.azure.com/git-for-windows/git/_apis/build/builds"
+ $id = ((Invoke-WebRequest -UseBasicParsing "${urlbase}?definitions=22&statusFilter=completed&resultFilter=succeeded&`$top=1").content | ConvertFrom-JSON).value[0].id
+ $downloadUrl = ((Invoke-WebRequest -UseBasicParsing "${urlbase}/$id/artifacts").content | ConvertFrom-JSON).value[1].resource.downloadUrl
+ (New-Object Net.WebClient).DownloadFile($downloadUrl,"git-sdk-64-minimal.zip")
+ Expand-Archive git-sdk-64-minimal.zip -DestinationPath . -Force
+ Remove-Item git-sdk-64-minimal.zip