Skip to content

Commit 8bff28d

Browse files
committed
Merge branch 'master' into feature/improved-exception-handling
2 parents ad98f23 + c032ef3 commit 8bff28d

File tree

58 files changed

+376
-868
lines changed

Some content is hidden

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

58 files changed

+376
-868
lines changed

GitVersionCore.Tests/BuildServers/BuildServerBaseTests.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public override bool CanApplyToCurrentContext()
3535
throw new NotImplementedException();
3636
}
3737

38-
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
39-
{
40-
throw new NotImplementedException();
41-
}
42-
4338
public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
4439
{
4540
return versionToUseForBuildNumber;

GitVersionCore.Tests/BuildServers/ContinuaCiTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ public class ContinuaCiTests
88
[Test]
99
public void GenerateBuildVersion()
1010
{
11-
var authentication = new Authentication();
12-
var versionBuilder = new ContinuaCi(authentication);
11+
var versionBuilder = new ContinuaCi();
1312
var continuaCiVersion = versionBuilder.GenerateSetVersionMessage("0.0.0-Beta4.7");
1413
Assert.AreEqual("@@continua[setBuildVersion value='0.0.0-Beta4.7']", continuaCiVersion);
1514
}

GitVersionCore.Tests/BuildServers/MyGetTests.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,23 @@ public class MyGetTests
77
[Test]
88
public void Develop_branch()
99
{
10-
var authentication = new Authentication();
11-
var versionBuilder = new MyGet(authentication);
10+
var versionBuilder = new MyGet();
1211
var message = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4");
1312
Assert.AreEqual(null, message);
1413
}
1514

1615
[Test]
1716
public void EscapeValues()
1817
{
19-
var authentication = new Authentication();
20-
var versionBuilder = new MyGet(authentication);
18+
var versionBuilder = new MyGet();
2119
var message = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
2220
Assert.AreEqual("##myget[setParameter name='GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", message[0]);
2321
}
2422

2523
[Test]
2624
public void BuildNumber()
2725
{
28-
var authentication = new Authentication();
29-
var versionBuilder = new MyGet(authentication);
26+
var versionBuilder = new MyGet();
3027
var message = versionBuilder.GenerateSetParameterMessage("LegacySemVerPadded", "0.8.0-unstable568");
3128
Assert.AreEqual("##myget[buildNumber '0.8.0-unstable568']", message[1]);
3229
}

GitVersionCore.Tests/BuildServers/TeamCityTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ public class TeamCityTests
77
[Test]
88
public void Develop_branch()
99
{
10-
var authentication = new Authentication();
11-
var versionBuilder = new TeamCity(authentication);
10+
var versionBuilder = new TeamCity();
1211
var tcVersion = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4");
1312
Assert.AreEqual("##teamcity[buildNumber '0.0.0-Unstable4']", tcVersion);
1413
}
1514

1615
[Test]
1716
public void EscapeValues()
1817
{
19-
var authentication = new Authentication();
20-
var versionBuilder = new TeamCity(authentication);
18+
var versionBuilder = new TeamCity();
2119
var tcVersion = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
2220
Assert.AreEqual("##teamcity[setParameter name='GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", tcVersion[0]);
2321
Assert.AreEqual("##teamcity[setParameter name='system.GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", tcVersion[1]);

GitVersionCore.Tests/ConfigProviderTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
[TestFixture]
1414
public class ConfigProviderTests
1515
{
16-
string gitDirectory;
16+
string repoPath;
1717
IFileSystem fileSystem;
1818

1919
[SetUp]
2020
public void Setup()
2121
{
2222
fileSystem = new TestFileSystem();
23-
gitDirectory = "c:\\MyGitRepo\\.git";
23+
repoPath = "c:\\MyGitRepo";
2424
}
2525

2626
[Test]
@@ -41,7 +41,7 @@ public void CanReadDocument()
4141
";
4242
SetupConfigFileContent(text);
4343

44-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
44+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
4545
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinor);
4646
config.NextVersion.ShouldBe("2.0.0");
4747
config.TagPrefix.ShouldBe("[vV|version-]");
@@ -61,7 +61,7 @@ public void CanReadOldDocument()
6161
release-branch-tag: rc
6262
";
6363
SetupConfigFileContent(text);
64-
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(gitDirectory, fileSystem));
64+
var error = Should.Throw<OldConfigurationException>(() => ConfigurationProvider.Provide(repoPath, fileSystem));
6565
error.Message.ShouldContainWithoutWhitespace(@"GitVersionConfig.yaml contains old configuration, please fix the following errors:
6666
assemblyVersioningScheme has been replaced by assembly-versioning-scheme
6767
develop-branch-tag has been replaced by branch specific configuration.See https://github.com/ParticularLabs/GitVersion/wiki/Branch-Specific-Configuration
@@ -79,7 +79,7 @@ public void OverwritesDefaultsWithProvidedConfig()
7979
tag: dev";
8080
SetupConfigFileContent(text);
8181
var defaultConfig = new Config();
82-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
82+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
8383

8484
config.NextVersion.ShouldBe("2.0.0");
8585
config.AssemblyVersioningScheme.ShouldBe(defaultConfig.AssemblyVersioningScheme);
@@ -97,7 +97,7 @@ public void CanProvideConfigForNewBranch()
9797
bug[/-]:
9898
tag: bugfix";
9999
SetupConfigFileContent(text);
100-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
100+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
101101

102102
config.Branches["bug[/-]"].Tag.ShouldBe("bugfix");
103103
}
@@ -106,7 +106,7 @@ public void CanProvideConfigForNewBranch()
106106
[MethodImpl(MethodImplOptions.NoInlining)]
107107
public void CanWriteOutEffectiveConfiguration()
108108
{
109-
var config = ConfigurationProvider.GetEffectiveConfigAsString(gitDirectory, fileSystem);
109+
var config = ConfigurationProvider.GetEffectiveConfigAsString(repoPath, fileSystem);
110110

111111
Approvals.Verify(config);
112112
}
@@ -116,7 +116,7 @@ public void CanReadDefaultDocument()
116116
{
117117
const string text = "";
118118
SetupConfigFileContent(text);
119-
var config = ConfigurationProvider.Provide(gitDirectory, fileSystem);
119+
var config = ConfigurationProvider.Provide(repoPath, fileSystem);
120120
config.AssemblyVersioningScheme.ShouldBe(AssemblyVersioningScheme.MajorMinorPatch);
121121
config.Branches["develop"].Tag.ShouldBe("unstable");
122122
config.Branches["release[/-]"].Tag.ShouldBe("beta");
@@ -156,6 +156,6 @@ public void VerifyAliases()
156156

157157
void SetupConfigFileContent(string text)
158158
{
159-
fileSystem.WriteAllText(Path.Combine(Directory.GetParent(gitDirectory).FullName, "GitVersionConfig.yaml"), text);
159+
fileSystem.WriteAllText(Path.Combine(repoPath, "GitVersionConfig.yaml"), text);
160160
}
161161
}

GitVersionCore.Tests/Fixtures/RemoteRepositoryFixture.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ public class RemoteRepositoryFixture : RepositoryFixtureBase
88
public string LocalRepositoryPath;
99
public IRepository LocalRepository;
1010

11+
public RemoteRepositoryFixture(Func<string, IRepository> builder, Config configuration)
12+
: base(builder, configuration)
13+
{
14+
CloneRepository();
15+
}
16+
1117
public RemoteRepositoryFixture(Config configuration)
1218
: base(CreateNewRepository, configuration)
1319
{

GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,33 @@ public void GivenARemoteGitRepositoryWithCommits_ThenClonedLocalShouldMatchRemot
1616
}
1717
}
1818

19+
[Test]
20+
public void GivenARemoteGitRepositoryWithCommitsAndBranches_ThenClonedLocalShouldMatchRemoteVersion()
21+
{
22+
using (var fixture = new RemoteRepositoryFixture(
23+
path =>
24+
{
25+
Repository.Init(path);
26+
Console.WriteLine("Created git repository at '{0}'", path);
27+
28+
var repo = new Repository(path);
29+
repo.MakeCommits(5);
30+
31+
repo.CreateBranch("develop");
32+
repo.CreateBranch("release-1.0");
33+
34+
repo.Checkout("release-1.0");
35+
repo.MakeCommits(5);
36+
37+
return repo;
38+
},
39+
new Config()))
40+
{
41+
fixture.AssertFullSemver("1.0.0-beta.1+5");
42+
fixture.AssertFullSemver("1.0.0-beta.1+5", fixture.LocalRepository);
43+
}
44+
}
45+
1946
[Test]
2047
public void GivenARemoteGitRepositoryAheadOfLocalRepository_ThenChangesShouldPull()
2148
{

GitVersionCore.Tests/JsonVersionBuilderTests.Json.approved.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"BranchName":"feature1",
1717
"Sha":"commitSha",
1818
"NuGetVersionV2":"1.2.3-unstable0004",
19-
"NuGetVersion":"1.2.3-unstable0004"
19+
"NuGetVersion":"1.2.3-unstable0004",
20+
"CommitDate":"2014-03-06"
2021
}

GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForPreRelease.approved.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"BranchName":"develop",
1717
"Sha":"commitSha",
1818
"NuGetVersionV2":"1.2.3-unstable0004",
19-
"NuGetVersion":"1.2.3-unstable0004"
19+
"NuGetVersion":"1.2.3-unstable0004",
20+
"CommitDate":"2014-03-06"
2021
}

GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeliveryModeForStable.approved.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"BranchName":"develop",
1717
"Sha":"commitSha",
1818
"NuGetVersionV2":"1.2.3",
19-
"NuGetVersion":"1.2.3"
19+
"NuGetVersion":"1.2.3",
20+
"CommitDate":"2014-03-06"
2021
}

GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForPreRelease.approved.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"BranchName":"develop",
1717
"Sha":"commitSha",
1818
"NuGetVersionV2":"1.2.3-unstable0005",
19-
"NuGetVersion":"1.2.3-unstable0005"
19+
"NuGetVersion":"1.2.3-unstable0005",
20+
"CommitDate":"2014-03-06"
2021
}

GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStable.approved.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"BranchName":"develop",
1717
"Sha":"commitSha",
1818
"NuGetVersionV2":"1.2.3-ci0005",
19-
"NuGetVersion":"1.2.3-ci0005"
19+
"NuGetVersion":"1.2.3-ci0005",
20+
"CommitDate":"2014-03-06"
2021
}

GitVersionCore.Tests/VariableProviderTests.ProvidesVariablesInContinuousDeploymentModeForStableWhenCurrentCommitIsTagged.approved.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"BranchName":"",
1717
"Sha":"commitSha",
1818
"NuGetVersionV2":"1.2.3",
19-
"NuGetVersion":"1.2.3"
19+
"NuGetVersion":"1.2.3",
20+
"CommitDate":"2014-03-06"
2021
}

GitVersionCore/AssemblyVersioningScheme.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public enum AssemblyVersioningScheme
44
{
5-
MajorMinorPatchMetadata,
5+
MajorMinorPatchTag,
66
MajorMinorPatch,
77
MajorMinor,
88
Major

GitVersionCore/AssemblyVersionsGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public static string GetAssemblyVersion(
1616
return string.Format("{0}.{1}.0.0", sv.Major, sv.Minor);
1717
case AssemblyVersioningScheme.MajorMinorPatch:
1818
return string.Format("{0}.{1}.{2}.0", sv.Major, sv.Minor, sv.Patch);
19-
case AssemblyVersioningScheme.MajorMinorPatchMetadata:
20-
return string.Format("{0}.{1}.{2}.{3}", sv.Major, sv.Minor, sv.Patch, sv.BuildMetaData.CommitsSinceTag ?? 0);
19+
case AssemblyVersioningScheme.MajorMinorPatchTag:
20+
return string.Format("{0}.{1}.{2}.{3}", sv.Major, sv.Minor, sv.Patch, sv.PreReleaseTag.Number ?? 0);
2121
default:
2222
throw new ArgumentException(string.Format("Unexpected value ({0}).", scheme), "scheme");
2323
}

GitVersionCore/BuildServers/AppVeyor.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,11 @@
66

77
public class AppVeyor : BuildServerBase
88
{
9-
Authentication authentication;
10-
11-
public AppVeyor(Authentication authentication)
12-
{
13-
this.authentication = authentication;
14-
}
15-
169
public override bool CanApplyToCurrentContext()
1710
{
1811
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPVEYOR"));
1912
}
2013

21-
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
22-
{
23-
if (string.IsNullOrEmpty(gitDirectory))
24-
{
25-
throw new WarningException("Failed to find .git directory on agent.");
26-
}
27-
28-
GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch);
29-
}
30-
3114
public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
3215
{
3316
var buildNumber = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_NUMBER");

GitVersionCore/BuildServers/BuildServerBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
public abstract class BuildServerBase : IBuildServer
66
{
77
public abstract bool CanApplyToCurrentContext();
8-
public abstract void PerformPreProcessingSteps(string gitDirectory, bool noFetch);
98
public abstract string GenerateSetVersionMessage(string versionToUseForBuildNumber);
109
public abstract string[] GenerateSetParameterMessage(string name, string value);
1110

GitVersionCore/BuildServers/BuildServerList.cs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,16 @@
55

66
public static class BuildServerList
77
{
8-
static List<IBuildServer> BuildServers;
9-
10-
public static Func<Authentication, IEnumerable<IBuildServer>> Selector = arguments => DefaultSelector(arguments);
11-
12-
public static void ResetSelector()
13-
{
14-
Selector = DefaultSelector;
15-
}
16-
17-
public static IEnumerable<IBuildServer> GetApplicableBuildServers(Authentication authentication)
8+
static List<IBuildServer> BuildServers = new List<IBuildServer>
189
{
19-
return Selector(authentication);
20-
}
10+
new ContinuaCi(),
11+
new TeamCity(),
12+
new AppVeyor(),
13+
new MyGet()
14+
};
2115

22-
static IEnumerable<IBuildServer> DefaultSelector(Authentication authentication)
16+
public static IEnumerable<IBuildServer> GetApplicableBuildServers()
2317
{
24-
if (BuildServers == null)
25-
{
26-
BuildServers = new List<IBuildServer>
27-
{
28-
new ContinuaCi(authentication),
29-
new TeamCity(authentication),
30-
new AppVeyor(authentication),
31-
new MyGet(authentication)
32-
};
33-
}
34-
3518
var buildServices = new List<IBuildServer>();
3619

3720
foreach (var buildServer in BuildServers)

GitVersionCore/BuildServers/ContinuaCi.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44

55
public class ContinuaCi : BuildServerBase
66
{
7-
Authentication authentication;
8-
9-
public ContinuaCi(Authentication authentication)
10-
{
11-
this.authentication = authentication;
12-
}
13-
147
public override bool CanApplyToCurrentContext()
158
{
169
const string KeyName = @"Software\VSoft Technologies\Continua CI Agent";
@@ -28,16 +21,6 @@ public override bool CanApplyToCurrentContext()
2821
return false;
2922
}
3023

31-
public override void PerformPreProcessingSteps(string gitDirectory, bool noFetch)
32-
{
33-
if (string.IsNullOrEmpty(gitDirectory))
34-
{
35-
throw new WarningException("Failed to find .git directory on agent");
36-
}
37-
38-
GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch);
39-
}
40-
4124
public override string[] GenerateSetParameterMessage(string name, string value)
4225
{
4326
return new[]

GitVersionCore/BuildServers/IBuildServer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
public interface IBuildServer
66
{
77
bool CanApplyToCurrentContext();
8-
void PerformPreProcessingSteps(string gitDirectory, bool noFetch);
98
string GenerateSetVersionMessage(string versionToUseForBuildNumber);
109
string[] GenerateSetParameterMessage(string name, string value);
1110

0 commit comments

Comments
 (0)