Skip to content

Commit bc74ac2

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 1518e4d + 35abfc8 commit bc74ac2

30 files changed

+615
-124
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ works out the [semantic version][semver] of the commit being built.
88
[![Build status][appveyor-badge]][appveyor]
99
[![Build Status][travis-badge]][travis]
1010

11-
| | Stable | Pre-release |
12-
| -------------------------: | :---------------------------------: | :---------------------------------------: |
13-
| **Docs** | [![Docs][docs-badge]][docs] | [![Docs][docs-pre-badge]][docs-pre] |
14-
| **GitHub Release** | - | [![GitHub release][gh-rel-badge]][gh-rel] |
15-
| **GitVersion.Portable** | [![Chocolatey][choco-badge]][choco] | [![Chocolatey][choco-pre-badge]][choco] |
16-
| **GitVersionTask** | [![NuGet][gvt-badge]][gvt] | [![NuGet][gvt-pre-badge]][gvt] |
17-
| **GitVersion.CommandLine** | [![NuGet][gvc-badge]][gvc] | [![NuGet][gvc-pre-badge]][gvc] |
18-
| **Gem** | [![Gem][gem-badge]][gem] | - |
19-
| **Homebrew** | [![homebrew][brew-badge]][brew] | - |
11+
| | Stable | Pre-release |
12+
| -------------------------: | :---------------------------------------: | :---------------------------------------: |
13+
| **Docs** | [![Docs][docs-badge]][docs] | [![Docs][docs-pre-badge]][docs-pre] |
14+
| **GitHub Release** | [![GitHub release][gh-rel-badge]][gh-rel] | - |
15+
| **GitVersion.Portable** | [![Chocolatey][choco-badge]][choco] | [![Chocolatey][choco-pre-badge]][choco] |
16+
| **GitVersionTask** | [![NuGet][gvt-badge]][gvt] | [![NuGet][gvt-pre-badge]][gvt] |
17+
| **GitVersion.CommandLine** | [![NuGet][gvc-badge]][gvc] | [![NuGet][gvc-pre-badge]][gvc] |
18+
| **Gem** | [![Gem][gem-badge]][gem] | - |
19+
| **Homebrew** | [![homebrew][brew-badge]][brew] | - |
2020

2121
## Compatibility
2222
GitVersion works on Mac, Linux with Mono and Windows.
@@ -29,7 +29,7 @@ You likely need to install `libcurl3`. Run `sudo get-get install libcurl3`
2929

3030
## Quick Links
3131
- [Documentation][docs]
32-
[Contributing][contribute]
32+
- [Contributing][contribute]
3333
- [Why GitVersion][why]
3434
- [Usage][usage]
3535
- [How it works][how]

docs/usage/command-line.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
# Command Line
22

3-
If you want a command line version installed on your machine then you can use [Chocolatey](http://chocolatey.org) to install GitVersion
3+
If you want a command line version installed on your machine then you can use [Chocolatey](http://chocolatey.org) or [Homebrew](https://brew.sh/) to install GitVersion.
44

5-
Available on [Chocolatey](http://chocolatey.org) under [GitVersion.Portable](http://chocolatey.org/packages/GitVersion.Portable)
5+
## Chocolatey
66

7-
> choco install GitVersion.Portable
7+
Available on [Chocolatey](http://chocolatey.org) under [GitVersion.Portable](http://chocolatey.org/packages/GitVersion.Portable).
8+
9+
```shell
10+
choco install GitVersion.Portable
11+
```
812

913
Switches are available with `GitVersion /?`
1014

15+
## Homebrew
16+
17+
To install GitVersion with [Homebrew](https://brew.sh/), type:
18+
19+
```shell
20+
brew install gitversion
21+
```
22+
23+
Switches are available with `gitversion --help`. Even though the documentation uses a slash `/` for all switches, you need to use a dash `-` instead, since `/` is interpreted as a root path on POSIX based operating systems.
24+
1125
## Output
1226

1327
By default GitVersion returns a json object to stdout containing all the [variables](../more-info/variables.md) which GitVersion generates. This works great if you want to get your build scripts to parse the json object then use the variables, but there is a simpler way.
1428

1529
`GitVersion.exe /output buildserver` will change the mode of GitVersion to write out the variables to whatever build server it is running in. You can then use those variables in your build scripts or run different tools to create versioned NuGet packages or whatever you would like to do. See [build servers](../build-server-support/build-server-support.md) for more information about this.
1630

1731
## Inject version metadata into the assembly
18-
`GitVersion.exe /updateassemblyinfo` will recursively search for all `AssemblyInfo.cs` or `AssemblyInfo.vb` files in the git repo and update them.
32+
`GitVersion.exe /updateassemblyinfo` will recursively search for all `AssemblyInfo.cs` or `AssemblyInfo.vb` files in the git repo and update them.
1933
It will update the following assembly attributes:
2034

2135
* `AssemblyVersion` will be set to the `AssemblySemVer` variable.
@@ -24,15 +38,15 @@ It will update the following assembly attributes:
2438

2539
Note that contrary to when using the [MSBuild Task](msbuild-task.md) the attributes must already exist in the `AssemblyInfo.cs` or `AssemblyInfo.vb` files prior to calling GitVersion.
2640

27-
By adding `/updateassemblyinfo <filenames>` the name of AssemblyInfo file to update can be set. This switch can accept multiple files with the path to the file specified relative to the working directory.
41+
By adding `/updateassemblyinfo <filenames>` the name of AssemblyInfo file to update can be set. This switch can accept multiple files with the path to the file specified relative to the working directory.
2842

2943
GitVersion can generate an assembly info source file for you if it does not already exist. Use the `/ensureassemblyinfo` switch alongside `/updateassemblyinfo <filename>`, if the filename specified does not exist it will be generated based on a known template that adds:
3044

3145
* `AssemblyVersion` will be set to the `AssemblySemVer` variable.
3246
* `AssemblyFileVersion` will be set to the `MajorMinorPatch` variable with a appended `.0`.
3347
* `AssemblyInformationalVersion` will be set to the `InformationalVersion` variable.
3448

35-
This can be done for *.cs, *.vb and *.fs files.
49+
This can be done for *.cs, *.vb and *.fs files.
3650

3751
When requesting that GitVersion generate an assembly info file you are limited to only specifying a single `<filename>` within the `/updateassemblyinfo` switch, this is to prevent the creation of mulitple assembly info files with the same assembly version attributes. If this occurs your build will fail.
3852

@@ -57,7 +71,7 @@ Will result in command line argument error
5771
Will iterate through each file and update known attributes (`AssemblyVersion`, `AssemblyFileVersion`, `AssemblyInformationalVersion`).
5872

5973
## Override config
60-
`/overrideconfig [key=value]` will override appropriate key from 'GitVersion.yml'.
74+
`/overrideconfig [key=value]` will override appropriate key from 'GitVersion.yml'.
6175

6276
At the moment only `tag-prefix` option is supported. Read more about [Configuration](/configuration/).
6377

@@ -67,4 +81,4 @@ It will not change config file 'GitVersion.yml'.
6781
`GitVersion.exe /output json /overrideconfig tag-prefix=custom`
6882

6983
## Mono
70-
To use on mac or linux, install `mono-complete` then just run `mono GitVersion.exe`
84+
To use on mac or linux, install `mono-complete` then just run `mono GitVersion.exe`

src/GitVersion.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,8 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
551551
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
552552
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
553553
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
554+
<s:Boolean x:Key="/Default/Environment/UnitTesting/DisabledProviders/=NUnit3x/@EntryIndexedValue">False</s:Boolean>
555+
<s:Boolean x:Key="/Default/Environment/UnitTesting/NUnitProvider/UseCustomNUnit/@EntryValue">False</s:Boolean>
554556
<s:Boolean x:Key="/Default/Environment/UnitTesting/SeparateAppDomainPerAssembly/@EntryValue">True</s:Boolean>
555557
<s:Boolean x:Key="/Default/Environment/UnitTesting/ShadowCopy/@EntryValue">False</s:Boolean>
556558

src/GitVersionCore.Tests/BuildServers/EnvironmentVariableJenkinsTests.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class EnvironmentVariableJenkinsTests
99
string key = "JENKINS_URL";
1010
string branch = "GIT_BRANCH";
1111
string localBranch = "GIT_LOCAL_BRANCH";
12+
string pipelineBranch = "BRANCH_NAME";
1213

1314
private void SetEnvironmentVariableForDetection()
1415
{
@@ -60,4 +61,28 @@ public void JenkinsTakesLocalBranchNameNotRemoteName()
6061
Environment.SetEnvironmentVariable(branch, branchOrig);
6162
Environment.SetEnvironmentVariable(localBranch, localBranchOrig);
6263
}
64+
65+
[Test]
66+
public void JenkinsTakesBranchNameInPipelineAsCode()
67+
{
68+
// Save original values so they can be restored
69+
string branchOrig = Environment.GetEnvironmentVariable(branch);
70+
string localBranchOrig = Environment.GetEnvironmentVariable(localBranch);
71+
string pipelineBranchOrig = Environment.GetEnvironmentVariable(pipelineBranch);
72+
73+
// Set BRANCH_NAME in pipeline mode
74+
Environment.SetEnvironmentVariable(pipelineBranch, "master");
75+
// When Jenkins uses a Pipeline, GIT_BRANCH and GIT_LOCAL_BRANCH are not set:
76+
Environment.SetEnvironmentVariable(branch, null);
77+
Environment.SetEnvironmentVariable(localBranch, null);
78+
79+
// Test Jenkins GetCurrentBranch method now returns BRANCH_NAME
80+
var j = new Jenkins();
81+
j.GetCurrentBranch(true).ShouldBe("master");
82+
83+
// Restore environment variables
84+
Environment.SetEnvironmentVariable(branch, branchOrig);
85+
Environment.SetEnvironmentVariable(localBranch, localBranchOrig);
86+
Environment.SetEnvironmentVariable(pipelineBranch, pipelineBranchOrig);
87+
}
6388
}

src/GitVersionCore.Tests/ConfigProviderTests.CanWriteOutEffectiveConfiguration.approved.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ branches:
4747
tag: PullRequest
4848
increment: Inherit
4949
prevent-increment-of-merged-branch-version: false
50-
tag-number-pattern: '[/-](?<number>\d+)[-/]'
50+
tag-number-pattern: '[/-](?<number>\d+)'
5151
track-merge-target: false
5252
regex: (pull|pull\-requests|pr)[/-]
5353
tracks-release-branches: false
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
namespace GitVersionCore.Tests
2+
{
3+
using System;
4+
using GitTools;
5+
using GitTools.Testing;
6+
using GitVersion;
7+
using NUnit.Framework;
8+
using Shouldly;
9+
10+
[TestFixture]
11+
public class GitRepoMetadataProviderTests
12+
{
13+
[Test]
14+
public void FindsCorrectMergeBaseForForwardMerge()
15+
{
16+
//*9dfb8b4 49 minutes ago(develop)
17+
//*54f21b2 53 minutes ago
18+
// |\
19+
// | | *a219831 51 minutes ago(HEAD -> release-2.0.0)
20+
// | |/
21+
// | *4441531 54 minutes ago
22+
// | *89840df 56 minutes ago
23+
// |/
24+
//*91bf945 58 minutes ago(master)
25+
using (var fixture = new EmptyRepositoryFixture())
26+
{
27+
fixture.MakeACommit("initial");
28+
fixture.BranchTo("develop");
29+
var expectedReleaseMergeBase = fixture.Repository.Head.Tip;
30+
31+
// Create release from develop
32+
fixture.BranchTo("release-2.0.0");
33+
34+
// Make some commits on release
35+
fixture.MakeACommit("release 1");
36+
fixture.MakeACommit("release 2");
37+
var expectedDevelopMergeBase = fixture.Repository.Head.Tip;
38+
39+
// First forward merge release to develop
40+
fixture.Checkout("develop");
41+
fixture.MergeNoFF("release-2.0.0");
42+
43+
// Make some new commit on release
44+
fixture.Checkout("release-2.0.0");
45+
fixture.MakeACommit("release 3 - after first merge");
46+
47+
// Make new commit on develop
48+
fixture.Checkout("develop");
49+
50+
// Checkout to release (no new commits)
51+
fixture.Checkout("release-2.0.0");
52+
53+
var develop = fixture.Repository.FindBranch("develop");
54+
var release = fixture.Repository.FindBranch("release-2.0.0");
55+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository)
56+
.FindMergeBase(release, develop);
57+
58+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository)
59+
.FindMergeBase(develop, release);
60+
61+
fixture.Repository.DumpGraph(Console.WriteLine);
62+
63+
releaseBranchMergeBase.ShouldBe(expectedReleaseMergeBase);
64+
developMergeBase.ShouldBe(expectedDevelopMergeBase);
65+
}
66+
}
67+
68+
[Test]
69+
public void FindsCorrectMergeBaseForForwardMergeMovesOn()
70+
{
71+
//*9dfb8b4 49 minutes ago(develop)
72+
//*54f21b2 53 minutes ago
73+
// |\
74+
// | | *a219831 51 minutes ago(HEAD -> release-2.0.0)
75+
// | |/
76+
// | *4441531 54 minutes ago
77+
// | *89840df 56 minutes ago
78+
// |/
79+
//*91bf945 58 minutes ago(master)
80+
using (var fixture = new EmptyRepositoryFixture())
81+
{
82+
fixture.MakeACommit("initial");
83+
fixture.BranchTo("develop");
84+
var expectedReleaseMergeBase = fixture.Repository.Head.Tip;
85+
86+
// Create release from develop
87+
fixture.BranchTo("release-2.0.0");
88+
89+
// Make some commits on release
90+
fixture.MakeACommit("release 1");
91+
fixture.MakeACommit("release 2");
92+
var expectedDevelopMergeBase = fixture.Repository.Head.Tip;
93+
94+
// First forward merge release to develop
95+
fixture.Checkout("develop");
96+
fixture.MergeNoFF("release-2.0.0");
97+
98+
// Make some new commit on release
99+
fixture.Checkout("release-2.0.0");
100+
fixture.MakeACommit("release 3 - after first merge");
101+
102+
// Make new commit on develop
103+
fixture.Checkout("develop");
104+
// Checkout to release (no new commits)
105+
fixture.MakeACommit("develop after merge");
106+
107+
// Checkout to release (no new commits)
108+
fixture.Checkout("release-2.0.0");
109+
110+
var develop = fixture.Repository.FindBranch("develop");
111+
var release = fixture.Repository.FindBranch("release-2.0.0");
112+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository)
113+
.FindMergeBase(release, develop);
114+
115+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository)
116+
.FindMergeBase(develop, release);
117+
118+
fixture.Repository.DumpGraph(Console.WriteLine);
119+
120+
releaseBranchMergeBase.ShouldBe(expectedReleaseMergeBase);
121+
developMergeBase.ShouldBe(expectedDevelopMergeBase);
122+
}
123+
}
124+
125+
[Test]
126+
public void FindsCorrectMergeBaseForMultipleForwardMerges()
127+
{
128+
//*403b294 44 minutes ago(develop)
129+
//|\
130+
//| *306b243 45 minutes ago(HEAD -> release-2.0.0)
131+
//| *4cf5969 47 minutes ago
132+
//| *4814083 51 minutes ago
133+
//* | cddd3cc 49 minutes ago
134+
//* | 2b2b52a 53 minutes ago
135+
//|\ \
136+
//| |/
137+
//| *8113776 54 minutes ago
138+
//| *3c0235e 56 minutes ago
139+
//|/
140+
//*f6f1283 58 minutes ago(master)
141+
142+
using (var fixture = new EmptyRepositoryFixture())
143+
{
144+
fixture.MakeACommit("initial");
145+
fixture.BranchTo("develop");
146+
var expectedReleaseMergeBase = fixture.Repository.Head.Tip;
147+
148+
// Create release from develop
149+
fixture.BranchTo("release-2.0.0");
150+
151+
// Make some commits on release
152+
fixture.MakeACommit("release 1");
153+
fixture.MakeACommit("release 2");
154+
155+
// First forward merge release to develop
156+
fixture.Checkout("develop");
157+
fixture.MergeNoFF("release-2.0.0");
158+
159+
// Make some new commit on release
160+
fixture.Checkout("release-2.0.0");
161+
fixture.Repository.MakeACommit("release 3 - after first merge");
162+
163+
// Make new commit on develop
164+
fixture.Checkout("develop");
165+
// Checkout to release (no new commits)
166+
fixture.Checkout("release-2.0.0");
167+
fixture.Checkout("develop");
168+
fixture.Repository.MakeACommit("develop after merge");
169+
170+
// Checkout to release (no new commits)
171+
fixture.Checkout("release-2.0.0");
172+
173+
// Make some new commit on release
174+
fixture.Repository.MakeACommit("release 4");
175+
fixture.Repository.MakeACommit("release 5");
176+
var expectedDevelopMergeBase = fixture.Repository.Head.Tip;
177+
178+
// Second merge release to develop
179+
fixture.Checkout("develop");
180+
fixture.MergeNoFF("release-2.0.0");
181+
182+
// Checkout to release (no new commits)
183+
fixture.Checkout("release-2.0.0");
184+
185+
var develop = fixture.Repository.FindBranch("develop");
186+
var release = fixture.Repository.FindBranch("release-2.0.0");
187+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository)
188+
.FindMergeBase(release, develop);
189+
190+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository)
191+
.FindMergeBase(develop, release);
192+
193+
fixture.Repository.DumpGraph(Console.WriteLine);
194+
195+
releaseBranchMergeBase.ShouldBe(expectedReleaseMergeBase);
196+
developMergeBase.ShouldBe(expectedDevelopMergeBase);
197+
}
198+
}
199+
}
200+
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<Compile Include="BuildServers\TeamCityTests.cs" />
9595
<Compile Include="Configuration\IgnoreConfigTests.cs" />
9696
<Compile Include="DynamicRepositoryTests.cs" />
97+
<Compile Include="GitRepoMetadataProviderTests.cs" />
9798
<Compile Include="GitToolsTestingExtensions.cs" />
9899
<Compile Include="DocumentationTests.cs" />
99100
<Compile Include="ConfigProviderTests.cs" />

0 commit comments

Comments
 (0)