Febiunz / AzureDevOpsExtensionGitClone

Azure DevOps extension to Clone a Git repository
GNU General Public License v3.0
1 stars 2 forks source link

Support for PR branches - refs/pull/1/merge #1

Closed LeMaciek closed 3 years ago

LeMaciek commented 4 years ago

In case o PR - Build.SourceBranch is refs/pull/1/merge In order to checkout this branch it's needed to add additional config for: remote.origin.fetch see: https://readify.net/blog/archive/reviewing-azure-devops-pull-requests-locally/

Febiunz commented 4 years ago

Did you try using "pr/1234" as the branch name? I think this will get the PR branch as needed.

That being sad: my question is why you would want an additional repository PR branch to be checked out in a build definition? The Azure DevOps approach is to create a branch policy and within this policy define a build that needs to be run. Or am I missing something in your question/issue?

LeMaciek commented 4 years ago

Here is our usecase - we are on azuredevops server 2019. We have a build with multiple jobs, but we don't want to checkout sources in each job (takes too long, reason: latency), so we switched off sync sources and get sources only in one job using your extension. Worked nice until we want to start using the build in the pr validation.

The problem It is not possible to just clone pr branches created by the server, as they are in refs/pull, which are not fetched by default. Unfortunately as per: https://stackoverflow.com/questions/20644613/why-does-git-clone-not-take-a-refspec it's not that straightforward.

Workaround

  1. clone master branch using extension
  2. in powershell task
    iex 'git config --add remote.origin.fetch +refs/pull/*/merge:refs/remotes/origin/pull/*/merge'
    iex 'git -c http.extraheader="Authorization: bearer $(System.AccessToken)" fetch origin'
    $sourceBranchFullName = '$(Build.SourceBranch)' -replace 'refs/',''
    iex 'git checkout $sourceBranchFullName'
Febiunz commented 4 years ago

Thanx for clearing that up. I understand the issue now. Nice workaround too! I will try to find some time to create a enhancement in the extension. Please feel free to submit a PR in this repo to enhance the functionality of this extension.

Febiunz commented 3 years ago

Closing the issue for now because a workaround is described above. If more users are experiencing the same problem I will try to find an enhancement.