parameters: 
  Workspace: $(Pipeline.Workspace)
  RepoOwner: not-set
  RepoName: vcpkg
  PRBranchName: not-set
  SetVcpkgRoot: true

steps:
  - pwsh: |
      Write-Host "git clone https://github.com/${{ parameters.RepoOwner }}/${{ parameters.RepoName }} ${{ parameters.Workspace }}/${{ parameters.RepoName }}"
      git clone https://github.com/${{ parameters.RepoOwner }}/${{ parameters.RepoName }} ${{ parameters.Workspace }}/${{ parameters.RepoName }}
      if ($LASTEXITCODE -ne 0) {
        Write-Error "Unable to check out vcpkg fork repo"
        exit $LASTEXITCODE
      }
    displayName: Clone vcpkg (${{ parameters.RepoOwner }}/${{ parameters.RepoName }})

  - ${{ if eq(parameters.SetVcpkgRoot, true) }}:
    - pwsh: |
        $vcpkgRoot = Resolve-Path "${{ parameters.Workspace }}/${{ parameters.RepoName }}"
        Write-Host "Set VCPKG_ROOT: $vcpkgRoot"
        Write-Host "##vso[task.setvariable variable=VCPKG_ROOT]$vcpkgRoot"
      displayName: Set VCPKG_ROOT

  # Check out the PR branch if it's already in remote. Ignore failures.
  - pwsh: |
      $ErrorActionPreference = "Continue"
      git checkout "origin/${{ parameters.PRBranchName }}" 2>&1 | Out-Null
      $LASTEXITCODE = 0 # This ignores any error from git checkout
      git status
    displayName: Checkout Previous PRBranch if it exists
    workingDirectory: ${{ parameters.Workspace }}/vcpkg