Skip to content

Commit b669e5f

Browse files
committed
Merge branch 'upstream/master' into master
1 parent 7997eee commit b669e5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+871
-217
lines changed

docs/git-branching-strategies/gitflow-examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Feature branches will take the feature branch name and use that as the pre-relea
1010

1111
Notice after the feature branch is merged, the version on `develop` is `1.3.0-alpha.3`. This is due to `develop` running in *continuous deployment* mode. If you configured `develop` to use *continuous delivery* the version would still be `1.3.0-alpha.1` and you would have to use release tags to increment the `alpha.1`.
1212

13-
You can see the different on the feature branch itself, notice the version is the same before and after the commit on the feature branch? Only the metadata has changed. If you released the feature branch artifacts then tagged the commit, the following commit would increase to `-beta.2`.
13+
You can see the difference on the feature branch itself, notice the version is the same before and after the commit on the feature branch? Only the metadata has changed. If you released the feature branch artifacts then tagged the commit, the following commit would increase to `-beta.2`.
1414

1515
## Pull Request
1616
Because feature branches are most likely pushed to a fork, we are showing the

docs/usage/msbuild-task.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The MSBuild Task for GitVersion — **GitVersionTask** — is a simple solution
44
you want to version your assemblies without writing any command line scripts or
55
modifying your build process.
66

7+
It currently works with desktop `MSBuild`. Support for CoreCLR with `dotnet build` is coming soon.
8+
79
## TL;DR
810

911
### Install the MSTask targets
@@ -16,6 +18,14 @@ From the Package Manager Console:
1618
Install-Package GitVersionTask
1719
```
1820

21+
If you're using `PackageReference` style NuGet dependencies (VS 2017+), add `<PrivateAssets>all</PrivateAssets>` to prevent the task from becoming a dependency of your package:
22+
23+
``` xml
24+
<PackageReference Include="GitVersionTask" Version="4.0.0-beta*">
25+
<PrivateAssets>All</PrivateAssets>
26+
</PackageReference>
27+
```
28+
1929
### Remove AssemblyInfo attributes
2030

2131
The next thing you need to do is to remove the `Assembly*Version` attributes from
@@ -115,6 +125,17 @@ However at MSBuild time these properties are mapped to MSBuild properties that
115125
are prefixed with `GitVersion_`. This prevents conflicts with other properties
116126
in the pipeline.
117127

128+
In addition, the following MSBuild properties are set when `UpdateVersionProperties` is true (the default):
129+
`Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`, `InformationalVersion`, `AssemblyVersion` and `FileVersion`. These are used by the built-in tasks for generating AssemblyInfo's and NuGet package versions.
130+
131+
132+
### NuGet packages
133+
The new SDK-style projects available for .NET Standard libraries (and multi-targeting), have the ability
134+
to create NuGet packages directly by using the `pack` target: `msbuild /t:pack`. The version is controled by the MSBuild properties described above.
135+
136+
GitVersionTask has the option to generate SemVer 2.0 compliant NuGet package versions by setting `UseFullSemVerForNuGet` to true in your project (this is off by default for compatibility). Some hosts, like MyGet, support SemVer 2.0 package versions but older NuGet clients and nuget.org do not.
137+
138+
118139
#### Accessing variables in MSBuild
119140

120141
Once `GitVersionTask.GetVersion` has been executed, the MSBuild properties can be
@@ -136,7 +157,7 @@ Build Server log in a format that the current Build Server can consume. See
136157

137158
## Conditional control tasks
138159

139-
Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo` and `GetVersion`
160+
Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo`, `UseFullSemVerForNuGet`, `UpdateVersionProperties` and `GetVersion`
140161
are checked before running these tasks.
141162

142163
You can disable `GitVersionTask.UpdateAssemblyInfo` by setting
@@ -150,6 +171,7 @@ this:
150171
...
151172
</PropertyGroup>
152173
```
174+
For SDK-style projects, `UpdateVersionProperties` controls setting the default variables: `Version`, `VersionPrefix`, `VersionSuffix`, `PackageVersion`, `InformationalVersion`, `AssemblyVersion` and `FileVersion`.
153175

154176
## My Git repository requires authentication. What should I do?
155177

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System.IO;
2+
using GitVersion;
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class DynamicRepositoryTests
7+
{
8+
string workDirectory;
9+
10+
11+
[SetUp]
12+
public void CreateTemporaryRepository()
13+
{
14+
// Note: we can't use guid because paths will be too long
15+
workDirectory = Path.Combine(Path.GetTempPath(), "DynRepoTests");
16+
}
17+
18+
19+
//[TearDown]
20+
//public void Cleanup()
21+
//{
22+
// Directory.Delete(workDirectory, true);
23+
//}
24+
25+
[Ignore("These tests are slow and fail on the second run in Test Explorer and need to be re-written")]
26+
[TestCase("GV_master_1", "https://github.com/GitTools/GitVersion", "master", "4783d325521463cd6cf1b61074352da84451f25d", "4.0.0+1126")]
27+
[TestCase("GV_master_2", "https://github.com/GitTools/GitVersion", "master", "3bdcd899530b4e9b37d13639f317da04a749e728", "4.0.0+1132")]
28+
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer)
29+
{
30+
var root = Path.Combine(workDirectory, name);
31+
var dynamicDirectory = Path.Combine(root, "dynamic");
32+
var workingDirectory = Path.Combine(root, "working");
33+
34+
// Clear upfront
35+
if (Directory.Exists(root))
36+
{
37+
Directory.Delete(root, true);
38+
}
39+
40+
Directory.CreateDirectory(dynamicDirectory);
41+
Directory.CreateDirectory(workingDirectory);
42+
43+
var executeCore = new ExecuteCore(new TestFileSystem());
44+
45+
var versionVariables = executeCore.ExecuteGitVersion(url, dynamicDirectory, null, targetBranch,
46+
false, workingDirectory, commitId);
47+
48+
Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
49+
}
50+
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<RootNamespace>GitVersionCore.Tests</RootNamespace>
1212
<AssemblyName>GitVersionCore.Tests</AssemblyName>
1313
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14-
<LangVersion>5</LangVersion>
14+
<LangVersion>6</LangVersion>
1515
<FileAlignment>512</FileAlignment>
1616
<TargetFrameworkProfile />
1717
<NuGetPackageImportStamp>
@@ -54,40 +54,12 @@
5454
<HintPath>..\packages\LibGit2Sharp.0.23.0-pre20160922233542\lib\net40\LibGit2Sharp.dll</HintPath>
5555
<Private>True</Private>
5656
</Reference>
57-
<Reference Include="Mono.Cecil, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
58-
<HintPath>..\packages\NUnit3TestAdapter.3.4.1\lib\Mono.Cecil.dll</HintPath>
59-
<Private>True</Private>
60-
</Reference>
61-
<Reference Include="Mono.Cecil.Mdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
62-
<HintPath>..\packages\NUnit3TestAdapter.3.4.1\lib\Mono.Cecil.Mdb.dll</HintPath>
63-
<Private>True</Private>
64-
</Reference>
65-
<Reference Include="Mono.Cecil.Pdb, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
66-
<HintPath>..\packages\NUnit3TestAdapter.3.4.1\lib\Mono.Cecil.Pdb.dll</HintPath>
67-
<Private>True</Private>
68-
</Reference>
69-
<Reference Include="Mono.Cecil.Rocks, Version=0.9.6.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
70-
<HintPath>..\packages\NUnit3TestAdapter.3.4.1\lib\Mono.Cecil.Rocks.dll</HintPath>
71-
<Private>True</Private>
72-
</Reference>
7357
<Reference Include="NSubstitute, Version=1.10.0.0, Culture=neutral, PublicKeyToken=92dd2e9066daa5ca, processorArchitecture=MSIL">
7458
<HintPath>..\packages\NSubstitute.1.10.0.0\lib\net45\NSubstitute.dll</HintPath>
7559
<Private>True</Private>
7660
</Reference>
77-
<Reference Include="nunit.engine, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
78-
<HintPath>..\packages\NUnit3TestAdapter.3.4.1\lib\nunit.engine.dll</HintPath>
79-
<Private>True</Private>
80-
</Reference>
81-
<Reference Include="nunit.engine.api, Version=3.0.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
82-
<HintPath>..\packages\NUnit3TestAdapter.3.4.1\lib\nunit.engine.api.dll</HintPath>
83-
<Private>True</Private>
84-
</Reference>
85-
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
86-
<HintPath>..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll</HintPath>
87-
<Private>True</Private>
88-
</Reference>
89-
<Reference Include="NUnit3.TestAdapter, Version=3.4.1.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
90-
<HintPath>..\packages\NUnit3TestAdapter.3.4.1\lib\NUnit3.TestAdapter.dll</HintPath>
61+
<Reference Include="nunit.framework, Version=3.6.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
62+
<HintPath>..\packages\NUnit.3.6.0\lib\net45\nunit.framework.dll</HintPath>
9163
<Private>True</Private>
9264
</Reference>
9365
<Reference Include="Shouldly, Version=2.7.0.0, Culture=neutral, PublicKeyToken=6042cbcb05cbc941, processorArchitecture=MSIL">
@@ -121,11 +93,13 @@
12193
<Compile Include="BuildServers\VsoAgentTests.cs" />
12294
<Compile Include="BuildServers\TeamCityTests.cs" />
12395
<Compile Include="Configuration\IgnoreConfigTests.cs" />
96+
<Compile Include="DynamicRepositoryTests.cs" />
12497
<Compile Include="GitToolsTestingExtensions.cs" />
12598
<Compile Include="DocumentationTests.cs" />
12699
<Compile Include="ConfigProviderTests.cs" />
127100
<Compile Include="GitVersionContextTests.cs" />
128101
<Compile Include="Helpers\DirectoryHelper.cs" />
102+
<Compile Include="IntegrationTests\FileSystemTests.cs" />
129103
<Compile Include="IntegrationTests\MainlineDevelopmentMode.cs" />
130104
<Compile Include="LogMessages.cs" />
131105
<Compile Include="Mocks\MockThreadSleep.cs" />

src/GitVersionCore.Tests/IntegrationTests/DevelopScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void InheritVersionFromReleaseBranch()
178178
fixture.AssertFullSemver("2.1.0-alpha.4");
179179
fixture.BranchTo("feature/MyFeature");
180180
fixture.MakeACommit();
181-
fixture.AssertFullSemver("2.1.0-MyFeature.1+3");
181+
fixture.AssertFullSemver("2.1.0-MyFeature.1+5");
182182
}
183183
}
184184
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.IO;
2+
using System.Text;
3+
4+
using GitVersion.Helpers;
5+
6+
using NUnit.Framework;
7+
8+
using Shouldly;
9+
10+
[TestFixture]
11+
public class FileSystemTests
12+
{
13+
public string TempFilePath { get; set; }
14+
15+
[SetUp]
16+
public void CreateTempFile()
17+
{
18+
TempFilePath = Path.GetTempFileName();
19+
}
20+
21+
[TearDown]
22+
public void Cleanup()
23+
{
24+
File.Delete(TempFilePath);
25+
}
26+
27+
[TestCase("utf-32")]
28+
[TestCase("utf-32BE")]
29+
[TestCase("utf-16")]
30+
[TestCase("utf-16BE")]
31+
[TestCase("utf-8")]
32+
public void WhenFileExistsWithEncodingPreamble_EncodingIsPreservedAfterWriteAll(string encodingName)
33+
{
34+
var encoding = Encoding.GetEncoding(encodingName);
35+
36+
File.WriteAllText(TempFilePath, "(-‸ლ)", encoding);
37+
38+
var fileSystem = new FileSystem();
39+
fileSystem.WriteAllText(TempFilePath, @"¯\(◉◡◔)/¯");
40+
41+
using (var stream = File.OpenRead(TempFilePath))
42+
{
43+
var preamble = encoding.GetPreamble();
44+
var bytes = new byte[preamble.Length];
45+
stream.Read(bytes, 0, preamble.Length);
46+
47+
bytes.ShouldBe(preamble);
48+
}
49+
}
50+
51+
[Test]
52+
public void WhenFileDoesNotExist_CreateWithUTF8WithPreamble()
53+
{
54+
var encoding = Encoding.UTF8;
55+
56+
var fileSystem = new FileSystem();
57+
fileSystem.WriteAllText(TempFilePath, "╚(ಠ_ಠ)=┐");
58+
59+
using (var stream = File.OpenRead(TempFilePath))
60+
{
61+
var preamble = encoding.GetPreamble();
62+
var bytes = new byte[preamble.Length];
63+
stream.Read(bytes, 0, preamble.Length);
64+
65+
bytes.ShouldBe(preamble);
66+
}
67+
}
68+
}

src/GitVersionCore.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
using GitTools.Testing;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using GitTools;
5+
using GitTools.Testing;
26
using GitVersion;
37
using GitVersionCore.Tests;
48
using LibGit2Sharp;
@@ -225,7 +229,7 @@ public void WhenReleaseBranchIsMergedIntoDevelopHighestVersionIsTakenWithIt()
225229
Commands.Checkout(fixture.Repository, "develop");
226230
fixture.Repository.MergeNoFF("release-1.0.0", Generate.SignatureNow());
227231

228-
fixture.AssertFullSemver("2.1.0-alpha.6");
232+
fixture.AssertFullSemver("2.1.0-alpha.11");
229233
}
230234
}
231235

@@ -329,6 +333,7 @@ public void HotfixOffReleaseBranchShouldNotResetCount()
329333
fixture.AssertFullSemver(config, "2.0.0-beta.7");
330334
}
331335
}
336+
332337
[Test]
333338
public void MergeOnReleaseBranchShouldNotResetCount()
334339
{
@@ -360,4 +365,105 @@ public void MergeOnReleaseBranchShouldNotResetCount()
360365
fixture.AssertFullSemver(config, "2.0.0-beta.2");
361366
}
362367
}
368+
369+
[Test]
370+
public void CommitOnDevelop_AfterReleaseBranchMergeToDevelop_ShouldNotResetCount()
371+
{
372+
var config = new Config
373+
{
374+
VersioningMode = VersioningMode.ContinuousDeployment
375+
};
376+
377+
using (var fixture = new EmptyRepositoryFixture())
378+
{
379+
fixture.Repository.MakeACommit("initial");
380+
fixture.Repository.CreateBranch("develop");
381+
Commands.Checkout(fixture.Repository, "develop");
382+
383+
// Create release from develop
384+
fixture.Repository.CreateBranch("release-2.0.0");
385+
Commands.Checkout(fixture.Repository, "release-2.0.0");
386+
fixture.AssertFullSemver(config, "2.0.0-beta.0");
387+
388+
// Make some commits on release
389+
fixture.Repository.MakeACommit("release 1");
390+
fixture.Repository.MakeACommit("release 2");
391+
fixture.AssertFullSemver(config, "2.0.0-beta.2");
392+
393+
// First merge release to develop
394+
Commands.Checkout(fixture.Repository, "develop");
395+
fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow());
396+
397+
// Make some new commit on release
398+
Commands.Checkout(fixture.Repository, "release-2.0.0");
399+
fixture.Repository.MakeACommit("release 3 - after first merge");
400+
fixture.AssertFullSemver(config, "2.0.0-beta.3");
401+
402+
// Make new commit on develop
403+
Commands.Checkout(fixture.Repository, "develop");
404+
fixture.Repository.MakeACommit("develop after merge");
405+
406+
// Checkout to release (no new commits)
407+
Commands.Checkout(fixture.Repository, "release-2.0.0");
408+
fixture.AssertFullSemver(config, "2.0.0-beta.3");
409+
410+
// Make some new commit on release
411+
fixture.Repository.MakeACommit("release 4");
412+
fixture.Repository.MakeACommit("release 5");
413+
fixture.AssertFullSemver(config, "2.0.0-beta.5");
414+
415+
// Second merge release to develop
416+
Commands.Checkout(fixture.Repository, "develop");
417+
fixture.Repository.MergeNoFF("release-2.0.0", Generate.SignatureNow());
418+
419+
// Checkout to release (no new commits)
420+
Commands.Checkout(fixture.Repository, "release-2.0.0");
421+
fixture.AssertFullSemver(config, "2.0.0-beta.5");
422+
}
423+
}
424+
425+
public void ReleaseBranchShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
426+
{
427+
using (var fixture = new EmptyRepositoryFixture())
428+
{
429+
fixture.Repository.MakeATaggedCommit("1.0");
430+
fixture.Repository.MakeACommit("+semver:major");
431+
fixture.Repository.MakeACommit();
432+
433+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/2.0"));
434+
435+
fixture.AssertFullSemver("2.0.0-beta.1+2");
436+
}
437+
}
438+
439+
[Test]
440+
public void ReleaseBranchWithACommitShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
441+
{
442+
using (var fixture = new EmptyRepositoryFixture())
443+
{
444+
fixture.Repository.MakeATaggedCommit("1.0");
445+
fixture.Repository.MakeACommit("+semver:major");
446+
fixture.Repository.MakeACommit();
447+
448+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/2.0"));
449+
450+
fixture.Repository.MakeACommit();
451+
452+
fixture.AssertFullSemver("2.0.0-beta.1+3");
453+
}
454+
}
455+
456+
[Test]
457+
public void ReleaseBranchedAtCommitWithSemverMessageShouldUseBranchNameVersion()
458+
{
459+
using (var fixture = new EmptyRepositoryFixture())
460+
{
461+
fixture.Repository.MakeATaggedCommit("1.0");
462+
fixture.Repository.MakeACommit("+semver:major");
463+
464+
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("release/2.0"));
465+
466+
fixture.AssertFullSemver("2.0.0-beta.1+1");
467+
}
468+
}
363469
}

0 commit comments

Comments
 (0)