Skip to content

Commit be73192

Browse files
committed
Merge remote-tracking branch 'particular/master'
2 parents 3e43817 + 0cb1c22 commit be73192

24 files changed

+277
-314
lines changed

BREAKING CHANGES.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ v3.0.0
33
- `AssemblyFileSemVer` variable removed, AssemblyVersioningScheme configuration value makes this variable obsolete
44
- Variables `ClassicVersion` and `ClassicVersionWithTag` removed
55
- MSBuild task arguments (AssemblyVersioningScheme, DevelopBranchTag, ReleaseBranchTag, TagPrefix, NextVersion) have been removed, use GitVersionConfig.yaml instead
6-
- GitVersionTask ReleaseDateAttribute no longer has OriginalReleaseDate
6+
- GitVersionTask ReleaseDateAttribute no longer exists

docs/more-info/variables.md

+6
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ For the `release/3.0.0` branch of GitVersion it shows:
2424
"NuGetVersion":"3.0.0-beta0001"
2525
}
2626
```
27+
28+
29+
#### Why is AssemblyVersion only set to Major.Minor?
30+
31+
This is a common approach that gives you the ability to roll out hot fixes to your assembly without breaking existing applications that may be referencing it. You are still able to get the full version number if you need to by looking at its file version number.
32+

docs/usage.md

+89-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Usage
2+
23
There are two main ways to consume GitVersion, the first is by running GitVersion.exe. The second is an MSBuild task. The MSBuild task is really easy to get up and running, simply install GitVersionTask from NuGet and it will integrate into your project and write out variables to your build server if it's running on one. The exe offers more options and works for not just .net projects.
34

45
- [A Command Line tool](#command-line)
56
- [An MSBuild Task](#msbuild-task)
67
- [A NuGet Library package](#nuget-library)
78
- [A Ruby Gem](#gem)
89

10+
911
## Command Line
12+
1013
If you want a command line version installed on your machine then you can use [Chocolatey](http://chocolatey.org) to install GitVersion
1114

1215
Available on [Chocolatey](http://chocolatey.org) under [GitVersion.Portable](http://chocolatey.org/packages/GitVersion.Portable)
@@ -15,57 +18,128 @@ Available on [Chocolatey](http://chocolatey.org) under [GitVersion.Portable](htt
1518
1619
Switches are available with `GitVersion /?`
1720

21+
1822
### Output
23+
1924
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.
2025

2126
`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.md) for more information about this.
2227

2328

2429
## MSBuild Task
25-
The MSBuild task will wire GitVersion into the MSBuild pipeline of a project and automatically stamp that assembly with the appropriate SemVer information
2630

2731
Available on [Nuget](https://www.nuget.org) under [GitVersionTask](https://www.nuget.org/packages/GitVersionTask/)
2832

2933
Install-Package GitVersionTask
3034

31-
Remove the `Assembly*Version` attributes from your `Properties\AssemblyInfo.cs` file. Sample default:
35+
The MSBuild task will wire GitVersion into the MSBuild pipeline of a project and perform several actions.
36+
37+
### 1. Inject version metadata into the assembly
38+
39+
Task Name: `GitVersionTask.UpdateAssemblyInfo`
40+
41+
#### AssemblyInfo Attributes
42+
43+
At build time a temporary AssemblyInfo.cs will be created that contains the appropriate SemVer information. This will will be included in the build pipeline.
44+
45+
Ensure you remove the `Assembly*Version` attributes from your `Properties\AssemblyInfo.cs` file so as to not get duplicate attribute warnings. Sample default:
3246

3347
[assembly: AssemblyVersion("1.0.0.0")]
3448
[assembly: AssemblyFileVersion("1.0.0.0")]
35-
[assembly: AssemblyInformationalVersion("1.0.0.0")]
49+
[assembly: AssemblyInformationalVersion("1.1.0+Branch.master.Sha.722aad3217bd49a6576b6f82f60884e612f9ba58")]
3650

37-
Make sure there is a tag somewhere on master named `v1.2.3` before `HEAD` (change the numbers as desired). Now when you build:
51+
Now when you build:
3852

39-
* AssemblyVersion will be set to 1.2.0.0 (i.e Major.Minor.0.0)
40-
* AssemblyFileVersion will be set to 1.2.3.0 (i.e Major.Minor.Patch)
41-
* AssemblyInformationalVersion will be set to `1.2.4+<commitcount>.Branch.<branchname>.Sha.<commithash>` where:
42-
* `<commitcount>` is the number of commits between the `v1.2.3` tag and `HEAD`.
43-
* `<branchname>` is the name of the branch you are on.
44-
* `<commithash>` is the commit hash of `HEAD`.
53+
* `AssemblyVersion` will be set to the `AssemblySemVer` variable.
54+
* `AssemblyFileVersion` will be set to the `MajorMinorPatch` variable with a appended `.0`.
55+
* `AssemblyInformationalVersion` will be set to the `InformationalVersion` variable.
4556

46-
Continue working as usual and when you release/deploy, tag the branch/release `v1.2.4`.
4757

48-
If you want to bump up the major or minor version, create a `GitVersionConfig.yaml` file in the root of your repo and inside of it on a single line enter `next-version: <version you want>`, for example `next-version: 3.0.0`
58+
#### Other injected Variables
4959

50-
### Why is AssemblyVersion only set to Major.Minor?
60+
All other [variables](more-info/variables.md) will be injected into a internal static class.
61+
62+
```
63+
namespace AssemblyName
64+
{
65+
[CompilerGenerated]
66+
internal static class GitVersionInformation
67+
{
68+
public static string Major = "1";
69+
public static string Minor = "1";
70+
public static string Patch = "0";
71+
...All other variables
72+
}
73+
}
74+
```
75+
76+
77+
#### Accessing injected Variables
78+
79+
**All variables**
80+
81+
```
82+
var assemblyName = assembly.GetName().Name;
83+
var gitVersionInformationType = assembly.GetType(assemblyName + ".GitVersionInformation");
84+
var fields = gitVersionInformationType.GetFields();
85+
86+
foreach (var field in fields)
87+
{
88+
Trace.WriteLine(string.Format("{0}: {1}", field.Name, field.GetValue(null)));
89+
}
90+
```
91+
92+
**Specific variable**
93+
94+
```
95+
var assemblyName = assembly.GetName().Name;
96+
var gitVersionInformationType = assembly.GetType(assemblyName + ".GitVersionInformation");
97+
var versionField = gitVersionInformationType.GetField("Major");
98+
Trace.WriteLine(versionField.GetValue(null));
99+
```
100+
101+
102+
### 2. Populate some MSBuild properties with version metadata
103+
104+
Task Name: `GitVersionTask.GetVersion`
105+
106+
At build time all the derived [variables](more-info/variables.md) will be written to MSBuild properties so the information can be used by other tooling in the build pipeline.
107+
108+
The class for `GitVersionTask.GetVersion` has a property for each variable. However at MSBuild time these properties a mapped to MSBuild properties that are prefixed with `GitVersion_`. This prevents conflicts with other properties in the pipeline.
109+
110+
#### Accessing variable in MSBuild
111+
112+
After `GitVersionTask.GetVersion` has executed the properties can be used in the standard way. For example:
113+
114+
<Message Text="GitVersion_InformationalVersion: $(GitVersion_InformationalVersion)"/>
115+
116+
117+
### 3. Communicate variables to current Build Server
118+
119+
Task Name: `GitVersionTask.WriteVersionInfoToBuildLog`
120+
121+
If, at build time, it is detected that the build is occurring inside a Build Server server then the [variables](more-info/variables.md) will be written to the build log in a format that the current Build Server can consume. See [Build Server Support](build-server-support.md).
51122

52-
This is a common approach that gives you the ability to roll out hot fixes to your assembly without breaking existing applications that may be referencing it. You are still able to get the full version number if you need to by looking at its file version number.
53123

54124
### My Git repository requires authentication. What do I do?
55125

56126
Set the environmental variables `GITVERSION_REMOTE_USERNAME` and `GITVERSION_REMOTE_PASSWORD` before the build is initiated.
57127

128+
58129
## NuGet Library
130+
59131
To use GitVersion from your own code.
60132

61133
**Warning, we are not semantically versioning this library and it should be considered unstable.**
62134

63135
It also is not currently documented. Please open an issue if you are consuming the library to let us know, and why you need to.
64136

137+
65138
## Gem
139+
66140
Just a gem wrapper around the command line to make it easier to consume from Rake.
67141

68-
**NOTE** This is currenly not being pushed.. Please get in touch if you are using this
142+
**NOTE** This is currently not being pushed.. Please get in touch if you are using this
69143

70144
If you want a Ruby gem version installed on your machine then you can use [Bundler](http://bundler.io/) or [Gem](http://rubygems.org/) to install the `gitversion` gem.
71145

src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

+1
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public void AssertFullSemver(string fullSemver, IRepository repository = null, s
131131
{
132132
if (repository != null)
133133
repository.DumpGraph();
134+
throw;
134135
}
135136
if (commitId == null)
136137
diagramBuilder.AppendLineFormat("note over {0} #D3D3D3: {1}", GetParticipant(Repository.Head.Name), fullSemver);

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
<Prefer32Bit>false</Prefer32Bit>
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<DebugType>pdbonly</DebugType>
30-
<Optimize>true</Optimize>
29+
<DebugType>full</DebugType>
30+
<Optimize>false</Optimize>
3131
<OutputPath>bin\Release\</OutputPath>
3232
<DefineConstants>TRACE</DefineConstants>
3333
<ErrorReport>prompt</ErrorReport>
3434
<WarningLevel>4</WarningLevel>
3535
<Prefer32Bit>false</Prefer32Bit>
36+
<DebugSymbols>true</DebugSymbols>
3637
</PropertyGroup>
3738
<ItemGroup>
3839
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">

src/GitVersionCore.Tests/IntegrationTests/DocumentationSamples.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void GitFlowMinorRelease()
139139

140140
// Make a commit after a tag should bump up the beta
141141
fixture.MakeACommit();
142-
fixture.AssertFullSemver("1.3.0-beta.2+1");
142+
fixture.AssertFullSemver("1.3.0-beta.2+2");
143143

144144
// Complete release
145145
fixture.Checkout("master");
@@ -195,7 +195,7 @@ public void GitFlowMajorRelease()
195195

196196
// Make a commit after a tag should bump up the beta
197197
fixture.MakeACommit();
198-
fixture.AssertFullSemver("2.0.0-beta.2+1");
198+
fixture.AssertFullSemver("2.0.0-beta.2+2");
199199

200200
// Complete release
201201
fixture.Checkout("master");
@@ -392,7 +392,7 @@ public void GitHubFlowMajorRelease()
392392

393393
// Make a commit after a tag should bump up the beta
394394
fixture.MakeACommit();
395-
fixture.AssertFullSemver("2.0.0-beta.2+1");
395+
fixture.AssertFullSemver("2.0.0-beta.2+3");
396396

397397
// Complete release
398398
fixture.Checkout("master");

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

+41-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void WhenReleaseBranchIsMergedIntoDevelopHighestVersionIsTakenWithIt()
205205
fixture.Repository.Checkout("develop");
206206
fixture.Repository.MergeNoFF("release-1.0.0", Constants.SignatureNow());
207207

208-
fixture.AssertFullSemver("2.1.0-unstable.0");
208+
fixture.AssertFullSemver("2.1.0-unstable.5");
209209
}
210210
}
211211

@@ -256,15 +256,53 @@ public void WhenMergingReleaseBackToDevShouldNotResetBetaVersion()
256256

257257
fixture.Repository.MakeCommits(1);
258258

259-
fixture.AssertFullSemver("2.0.0-beta.2+1");
259+
fixture.AssertFullSemver("2.0.0-beta.2+2");
260260

261261
//merge down to develop
262262
fixture.Repository.Checkout("develop");
263263
fixture.Repository.MergeNoFF("release-2.0.0", Constants.SignatureNow());
264264

265265
//but keep working on the release
266266
fixture.Repository.Checkout("release-2.0.0");
267-
fixture.AssertFullSemver("2.0.0-beta.2+1");
267+
fixture.AssertFullSemver("2.0.0-beta.2+2");
268+
}
269+
}
270+
271+
[Test]
272+
public void HotfixOffReleaseBranchShouldNotResetCount()
273+
{
274+
using (var fixture = new EmptyRepositoryFixture(new Config
275+
{
276+
VersioningMode = VersioningMode.ContinuousDeployment
277+
}))
278+
{
279+
const string TaggedVersion = "1.0.3";
280+
fixture.Repository.MakeATaggedCommit(TaggedVersion);
281+
fixture.Repository.CreateBranch("develop");
282+
fixture.Repository.Checkout("develop");
283+
284+
fixture.Repository.MakeCommits(1);
285+
286+
fixture.Repository.CreateBranch("release-2.0.0");
287+
fixture.Repository.Checkout("release-2.0.0");
288+
fixture.Repository.MakeCommits(1);
289+
290+
fixture.AssertFullSemver("2.0.0-beta.1");
291+
292+
//tag it to bump to beta 2
293+
fixture.Repository.MakeCommits(4);
294+
295+
fixture.AssertFullSemver("2.0.0-beta.5");
296+
297+
//merge down to develop
298+
fixture.Repository.CreateBranch("hotfix-2.0.0");
299+
fixture.Repository.MakeCommits(2);
300+
301+
//but keep working on the release
302+
fixture.Repository.Checkout("release-2.0.0");
303+
fixture.Repository.MergeNoFF("hotfix-2.0.0", Constants.SignatureNow());
304+
fixture.Repository.Branches.Remove(fixture.Repository.FindBranch("hotfix-2.0.0"));
305+
fixture.AssertFullSemver("2.0.0-beta.7");
268306
}
269307
}
270308
}

src/GitVersionCore.Tests/IntegrationTests/SupportBranchScenarios.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void WhenSupportIsBranchedAndTaggedFromAnotherSupportEnsureNewMinorIsUsed
6969
fixture.Repository.MakeACommit();
7070
fixture.Repository.MakeACommit();
7171

72-
fixture.AssertFullSemver("1.3.0+2");
72+
fixture.AssertFullSemver("1.3.1+2");
7373
}
7474
}
7575
}

src/GitVersionCore/Configuration/ConsoleAdapter.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ class ConsoleAdapter : IConsole
66
{
77
public void WriteLine(string msg)
88
{
9-
throw new NotImplementedException();
9+
Console.WriteLine(msg);
1010
}
1111

1212
public void WriteLine()
1313
{
14-
throw new NotImplementedException();
14+
Console.WriteLine();
1515
}
1616

1717
public void Write(string msg)
1818
{
19-
throw new NotImplementedException();
19+
Console.Write(msg);
2020
}
2121

2222
public string ReadLine()
2323
{
24-
throw new NotImplementedException();
24+
return Console.ReadLine();
2525
}
2626

2727
public IDisposable UseColor(ConsoleColor consoleColor)

src/GitVersionCore/NugetAssets/GitVersion.nuspec

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
<id>GitVersion</id>
55
<version>$version$</version>
66
<title>GitVersion</title>
7-
<authors>NServiceBus Ltd</authors>
8-
<owners>nservicebus, simoncropp</owners>
7+
<authors>GitTools and Contributors</authors>
8+
<owners>GitTools and Contributors</owners>
99
<licenseUrl>http://www.opensource.org/licenses/mit-license.php</licenseUrl>
10-
<projectUrl>http://github.com/Particular/GitVersion</projectUrl>
11-
<iconUrl>https://raw.github.com/Particular/GitVersion/master/Icons/package_icon.png</iconUrl>
10+
<projectUrl>https://github.com/GitTools/GitVersion</projectUrl>
11+
<iconUrl>https://raw.githubusercontent.com/GitTools/GitVersion/master/docs/img/package_icon.png</iconUrl>
1212
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1313
<description>Derives SemVer information from a repository following GitFlow or GitHubFlow.</description>
1414
<language>en-AU</language>
1515
<tags>Git, Versioning, GitVersion, GitFlowVersion, GitFlow, GitHubFlow, SemVer</tags>
16+
<releaseNotes>https://github.com/GitTools/GitVersion/releases</releaseNotes>
1617
</metadata>
17-
</package>
18+
</package>

src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public BaseVersion GetBaseVersion(GitVersionContext context)
5353
{
5454
baseVersionWithOldestSource = baseVersions
5555
.Where(v => v.Version.BaseVersionSource != null)
56-
.OrderBy(v => v.IncrementedVersion)
56+
.OrderByDescending(v => v.IncrementedVersion)
5757
.ThenByDescending(v => v.Version.BaseVersionSource.Committer.When)
5858
.First()
5959
.Version;

src/GitVersionExe.Tests/GitVersionExe.Tests.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
<WarningLevel>4</WarningLevel>
2323
</PropertyGroup>
2424
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25-
<DebugType>pdbonly</DebugType>
26-
<Optimize>true</Optimize>
25+
<DebugType>full</DebugType>
26+
<Optimize>false</Optimize>
2727
<OutputPath>bin\Release\</OutputPath>
2828
<DefineConstants>TRACE</DefineConstants>
2929
<ErrorReport>prompt</ErrorReport>
3030
<WarningLevel>4</WarningLevel>
31+
<DebugSymbols>true</DebugSymbols>
3132
</PropertyGroup>
3233
<ItemGroup>
3334
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">

0 commit comments

Comments
 (0)