parameters:
  - name: VSCODE_QUALITY
    type: string

steps:
  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
      - task: AzureKeyVault@1
        displayName: "Azure Key Vault: Get Secrets"
        inputs:
          azureSubscription: "vscode-builds-subscription"
          KeyVaultName: vscode-build-secrets
          SecretsFilter: "github-distro-mixin-password"

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
      - powershell: |
          . build/azure-pipelines/win32/exec.ps1
          $ErrorActionPreference = "Stop"
          "machine github.com`nlogin vscode`npassword $(github-distro-mixin-password)" | Out-File "$env:USERPROFILE\_netrc" -Encoding ASCII

          exec { git config user.email "vscode@microsoft.com" }
          exec { git config user.name "VSCode" }
        displayName: Prepare tooling

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
      - powershell: |
          . build/azure-pipelines/win32/exec.ps1
          $ErrorActionPreference = "Stop"

          exec { git fetch https://github.com/$(VSCODE_MIXIN_REPO).git $(VSCODE_DISTRO_REF) }
          Write-Host "##vso[task.setvariable variable=VSCODE_DISTRO_COMMIT;]$(git rev-parse FETCH_HEAD)"
          exec { git checkout FETCH_HEAD }
        condition: and(succeeded(), ne(variables.VSCODE_DISTRO_REF, ' '))
        displayName: Checkout override commit

  - ${{ if ne(parameters.VSCODE_QUALITY, 'oss') }}:
      - powershell: |
          . build/azure-pipelines/win32/exec.ps1
          $ErrorActionPreference = "Stop"
          exec { git pull --no-rebase https://github.com/$(VSCODE_MIXIN_REPO).git $(node -p "require('./package.json').distro") }
        displayName: Merge distro
