Skip to content

Commit 7b229fe

Browse files
Oren NovotnyJakeGinnivan
authored andcommitted
Handle VSO's pull requests. Need to check them out locally and they don't show up as a remote branch
1 parent ea0aa68 commit 7b229fe

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/GitVersionVsoTask/Run-GitVersion.ps1

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,36 @@ $loc = $($env:BUILD_SOURCESDIRECTORY)
2727
$branch = $($env:BUILD_SOURCEBRANCH)
2828
$commitId = $($env:BUILD_SOURCEVERSION)
2929

30-
$localBranch = $branch.Trim().Replace("refs/heads/", "")
30+
$localBranch = $branch.Trim().Replace("refs/heads/", "").Replace("refs/","")
3131

3232
Set-Location $loc
3333

34+
$haveLocalBranch = $false
3435
# VSO checks out the commit as a detached HEAD
3536
# loop through and checkout all branches and the one we want
36-
# then reset hard to get to the desired commit id
37+
# then reset merge to get to the desired commit id
3738
foreach ($remoteBranch in . git branch -r) {
38-
. git checkout $remoteBranch.Trim().Replace("origin/", "") 2>&1 | write-host
39+
40+
$lb = $remoteBranch.Trim().Replace("origin/", "")
41+
. git checkout $lb 2>&1 | write-host
3942

43+
# keep track of if we have a matching local branch
44+
# pull requests will not show up here
45+
if($lb -eq $localBranch) {
46+
$haveLocalBranch = $true
47+
}
4048
}
41-
. git checkout $localBranch 2>&1 | write-host
42-
. git reset --hard $commitId 2>&1 | write-host
49+
50+
# if we have a local branch, check that out and set it at the right commit
51+
if($haveLocalBranch){
52+
. git checkout $localBranch 2>&1 | write-host
53+
. git reset --merge $commitId 2>&1 | write-host
54+
} else {
55+
# try to create a local branch from this commit - likely a PR
56+
. git checkout -b $localBranch $commitId 2>&1 | write-host
57+
}
58+
59+
4360

4461
# Call GitVersion.exe
4562
$gvPath = Get-PathToGitVersionExe

src/GitVersionVsoTask/task.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"version": {
1515
"Major": "0",
1616
"Minor": "1",
17-
"Patch": "4"
17+
"Patch": "29"
1818
},
1919
"minimumAgentVersion": "1.83.0",
2020
"groups": [

0 commit comments

Comments
 (0)