Skip to content

Commit

Permalink
Prevent tag refs in $(GitBranch) for detached heads.
Browse files Browse the repository at this point in the history
  • Loading branch information
andersforsgren authored and kzu committed Sep 24, 2020
1 parent 75ef3eb commit 64fd2e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
will be used to find a base version.
Defaults to empty value (no ignoring).
$(GitNameRevOptions): Options passed to git name-rev when finding
a branch name for a commit (Detached head).
The default is '--refs=refs/heads/*'
meaning branch names only. For the legacy behavior where
$(GitBranch) for detached head can also be a tag name,
use '--refs=refs/*'.
Refs can be included and excluded, see git name-rev docs.
$(GitSkipCache): whether to cache the Git information determined
in a previous build in a GitInfo.cache for
performance reasons.
Expand Down Expand Up @@ -92,6 +100,8 @@

<GitCommitsIgnoreMerges Condition="'$(GitCommitsIgnoreMerges)' == ''">false</GitCommitsIgnoreMerges>

<GitNameRevOptions Condition="'$(GitNameRevOptions)' == ''">--refs=refs/heads/*</GitNameRevOptions>

<GitMinVersion>2.5.0</GitMinVersion>
</PropertyGroup>

Expand Down Expand Up @@ -428,7 +438,7 @@
</PropertyGroup>

<!-- CI systems may checkout the specific commit, rather than the branch, so we need to fallback -->
<Exec Command='$(GitExe) name-rev --name-only HEAD'
<Exec Command='$(GitExe) name-rev --name-only $(GitNameRevOptions) HEAD'
Condition=" '$(GitBranch)' == '' "
EchoOff='true'
StandardErrorImportance="low"
Expand Down
13 changes: 13 additions & 0 deletions src/GitInfo/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,16 @@ Available MSBuild customizations:
whether the branch and tags (if any)
will be used to find a base version.
Defaults to empty value (no ignoring).

$(GitNameRevOptions): Options passed to git name-rev when finding
a branch name for the current commit (Detached head).
The default is '--refs=refs/heads/*'
meaning branch names only. For legacy behavior where
$(GitBranch) for detached head can also be a tag name,
use '--refs=refs/*'.
Refs can be included and excluded, see git name-rev docs.

$(GitSkipCache): whether to cache the Git information determined
in a previous build in a GitInfo.cache for
performance reasons.
Defaults to empty value (no ignoring).

0 comments on commit 64fd2e4

Please sign in to comment.