Skip to content

Commit

Permalink
Add support for folder syntax for branches
Browse files Browse the repository at this point in the history
It's quite typical to name release branches like release/v....
This adds support for both forward and backslashes in the branch
name and skips them for determining the base version.

Fixes #101
  • Loading branch information
kzu committed Sep 20, 2020
1 parent d05f028 commit 0bcd7c1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,12 @@
Condition="'$(GitBaseVersion)' == '' And '$(GitIgnoreBranchVersion)' != 'true' ">

<PropertyGroup>
<_CandidateValue>$(GitBranch)</_CandidateValue>
<_IndexOfSlash>$(_CandidateValue.LastIndexOf('/'))</_IndexOfSlash>
<_IndexOfSlash Condition="'$(_IndexOfSlash)' == '-1'">$(_CandidateValue.LastIndexOf('\'))</_IndexOfSlash>
<_CandidateValue Condition="'$(_GitBranchIndexOfSlash)' != '-1'">$(_CandidateValue.Substring($([MSBuild]::Add($(_IndexOfSlash), 1))))</_CandidateValue>
<IsValidGitBaseVersion>
$([System.Text.RegularExpressions.Regex]::IsMatch($(GitBranch), $(_GitBaseVersionExpr)))
$([System.Text.RegularExpressions.Regex]::IsMatch($(_CandidateValue), $(_GitBaseVersionExpr)))
</IsValidGitBaseVersion>
<IsValidGitBaseVersion>$(IsValidGitBaseVersion.Trim())</IsValidGitBaseVersion>
</PropertyGroup>
Expand All @@ -622,7 +626,7 @@
Importance="low" Condition="'$(IsValidGitBaseVersion)' == 'false'" />

<PropertyGroup Condition="'$(IsValidGitBaseVersion)' == 'true'">
<GitBaseVersion>$(GitBranch)</GitBaseVersion>
<GitBaseVersion>$(_CandidateValue)</GitBaseVersion>
<GitBaseVersionSource>GitBranch</GitBaseVersionSource>
<GitSemVerSource>Branch</GitSemVerSource>
</PropertyGroup>
Expand Down

0 comments on commit 0bcd7c1

Please sign in to comment.