-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathcheckout-code.yml
27 lines (24 loc) · 1.41 KB
/
checkout-code.yml
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
steps:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema#checkout
- checkout: self
fetchDepth: 10
# Allow `script` steps to interact with the git remote (required for such operations to succeed on private repos).
# See: https://docs.microsoft.com/en-us/azure/devops/pipelines/scripts/git-commands?view=azure-devops&tabs=yaml#allow-scripts-to-access-the-system-token
persistCredentials: true
# Azure checks out the code from the PR but leaves us in a detached state.
# Because ddev cannot work in that state, we create a branch.
# Only applies to PRs
- script: git checkout -B azure/$(System.PullRequest.SourceBranch)
condition: eq(variables['Build.Reason'], 'PullRequest')
displayName: 'Create branch from PR'
# Azure pulls a commit hash via git fetch rather than clone so
# we checkout the branches we need which also gets us out of a
# detached HEAD state. This may be fixed soon, see:
# https://developercommunity.visualstudio.com/content/problem/373462/git-get-sources-shallow-fetch-is-broken-subject-to.html
- script: git fetch origin master && git checkout master
displayName: 'Fetch and checkout master'
# Switch to the pull request branch last. Also see:
# https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables#system-variables
- script: git checkout azure/$(System.PullRequest.SourceBranch)
condition: eq(variables['Build.Reason'], 'PullRequest')
displayName: 'Checkout branch'