Skip to content

Commit 0fb5b57

Browse files
Oren NovotnyJakeGinnivan
authored andcommitted
ensure local branch info is available
1 parent a88ae00 commit 0fb5b57

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/GitVersionVsoTask/Run-GitVersion.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,25 @@ $updateAssms = Convert-String $updateAssemblyInfo Boolean
2525

2626
$loc = $($env:BUILD_SOURCESDIRECTORY)
2727
$branch = $($env:BUILD_SOURCEBRANCH)
28+
$commitId = $($env:BUILD_SOURCEVERSION)
29+
30+
$localBranch = $branch.Trim().Replace("refs/heads/", "")
31+
32+
Set-Location $loc
33+
34+
# VSO checks out the commit as a detached HEAD
35+
# loop through and checkout all branches and the one we want
36+
# then reset hard to get to the desired commit id
37+
foreach ($remoteBranch in . git branch -r) {
38+
. git checkout $remoteBranch.Trim().Replace("origin/", "") 2>&1 | write-host
39+
40+
}
41+
. git checkout $localBranch 2>&1 | write-host
42+
. git reset --hard $commitId 2>&1 | write-host
2843

2944
# Call GitVersion.exe
3045
$gvPath = Get-PathToGitVersionExe
3146
Write-Output "Path to GitVersion.exe = $gvPath"
32-
Invoke-Tool -Path $gvPath -Arguments "`"$loc`" /output buildserver /nofetch /b $branch /updateAssemblyInfo $updateAssms $additionalArguments"
47+
Invoke-Tool -Path $gvPath -Arguments "`"$loc`" /output buildserver /nofetch /updateAssemblyInfo $updateAssms $additionalArguments"
3348

3449

0 commit comments

Comments
 (0)