Skip to content

Commit 6ba0a48

Browse files
committed
Allow opting-out of GitBranch default in CI
This should allow the old behavior, in case the new defaults disrupt some existing functionality.
1 parent 1e0e2f4 commit 6ba0a48

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ to customize the behavior:
205205
206206
$(GitRemote): name of remote to get repository url for. Defaults to 'origin'.
207207
208+
$(GitBranchCI): determines whether the branch name should be populated from default environment variables used by the CI system. Default to 'true'.
209+
208210
$(GitDefaultBranch): determines the base branch used to calculate commits on top of current branch. Defaults to 'main'.
209211
210212
$(GitVersionFile): determines the name of a file in the Git repository root used to provide the base version info. Defaults to 'GitInfo.txt'.

src/GitInfo/build/GitInfo.CI.targets

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
3+
<!--
4+
Uses well-known documented CI systems branch names to determine the current Git branch.
5+
Can be disabled by setting the GitBranchCI=false property, or setting GitBranch to a specific value.
6+
-->
47
<PropertyGroup Condition="'$(GitBranch)' == ''">
58
<!-- GitHub Actions: https://docs.github.com/en/actions/reference/environment-variables#default-environment-variables -->
69
<GitBranch Condition="'$(GitBranch)' == '' and '$(GITHUB_REF)' != '' and $(GITHUB_REF.Contains('refs/pull/'))">pr$(GITHUB_REF.Replace('refs/pull/', '').Replace('/merge', ''))</GitBranch>

src/GitInfo/build/GitInfo.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
2424
$(GitDefaultBranch): determines the base branch used to calculate commits on top of current branch. Defaults to 'main'.
2525
26+
$(GitBranchCI): determines whether the branch name should be populated from default environment variables used by the CI system. Default to 'true'.
27+
2628
$(GitVersionFile): determines the name of a file in the Git repository root used to provide the base version info. Defaults to 'GitInfo.txt'.
2729
2830
$(GitCommitsRelativeTo): optionally specifies an alternative directory for counting commits on top of the base version. Defaults to the $(GitVersionFile) directory.
@@ -116,7 +118,7 @@
116118
'$(BUDDY)' == 'true'">true</CI>
117119
</PropertyGroup>
118120

119-
<Import Project="GitInfo.CI.targets" Condition="$(CI)" />
121+
<Import Project="GitInfo.CI.targets" Condition="$(CI) and $(GitBranchCI) != 'false'" />
120122

121123
<Target Name="GitInfoReport" DependsOnTargets="GitVersion">
122124
<Message Importance="$(GitInfoReportImportance)" Text="Git Info:

src/GitInfo/readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Available MSBuild customizations:
9595
* You can get a list of your remotes by running `git remote -v` in your shell when inside your git repo.
9696
* Defaults to 'origin'.
9797

98+
$(GitBranchCI):
99+
* Determines whether the branch name should be populated from default environment variables used by the CI system. Default to 'true'.
98100

99101
$(GitDefaultBranch):
100102
* Specifies the base branch which is compared to your current branch (at time of build) to determine how many commits ahead the current branch is compared to base.

0 commit comments

Comments
 (0)