Skip to content

Commit 2d50fd0

Browse files
author
Jake Ginnivan
committed
Starting to implement wiki scenarios and deleting tests which are no longer needed
1 parent d67d562 commit 2d50fd0

19 files changed

+187
-506
lines changed

AcceptanceTests/AcceptanceTests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
<ItemGroup>
6161
<Compile Include="ExecCmdLineArgumentTest.cs" />
6262
<Compile Include="GitFlow\DevelopScenarios.cs" />
63+
<Compile Include="GitFlow\UncycloScenarios.cs" />
64+
<Compile Include="Helpers\Constants.cs" />
6365
<Compile Include="PullRequestInTeamCityTest.cs" />
6466
<Compile Include="EmptyRepositoryFixture.cs" />
6567
<Compile Include="Helpers\ExecutionResults.cs" />

AcceptanceTests/EmptyRepositoryFixture.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,29 @@ public EmptyRepositoryFixture()
1919
Repository = new Repository(RepositoryPath);
2020
Repository.Config.Set("user.name", "Test");
2121
Repository.Config.Set("user.email", "[email protected]");
22+
23+
var randomFile = Path.Combine(Repository.Info.WorkingDirectory, Guid.NewGuid().ToString());
24+
File.WriteAllText(randomFile, string.Empty);
25+
Repository.Index.Stage(randomFile);
26+
Repository.Commit("Initial Commit", new Signature("Test User", "[email protected]", DateTimeOffset.UtcNow));
2227
}
2328

2429
public void Dispose()
2530
{
2631
Repository.Dispose();
2732
try
2833
{
29-
Directory.Delete(RepositoryPath, true);
34+
//Directory.Delete(RepositoryPath, true);
3035
}
3136
catch (Exception e)
3237
{
3338
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message);
3439
}
3540
}
41+
42+
public ExecutionResults ExecuteGitVersion()
43+
{
44+
return GitVersionHelper.ExecuteIn(RepositoryPath);
45+
}
3646
}
3747
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
namespace AcceptanceTests.GitFlow
2+
{
3+
using GitHubFlowVersion.AcceptanceTests;
4+
using GitHubFlowVersion.AcceptanceTests.Helpers;
5+
using GitVersion;
6+
using LibGit2Sharp;
7+
using Shouldly;
8+
using Xunit;
9+
10+
public class UncycloScenarios
11+
{
12+
/// <summary>
13+
/// https://github.com/Particular/GitVersion/wiki/GitFlowExamples#minor-release
14+
/// </summary>
15+
/* These will be slightly out of sync because we need to make a commit to force a merge commit
16+
participant featureAbc
17+
participant develop
18+
participant release-1.3.0
19+
master -> master: tag 1.2.0
20+
master -> develop: merge
21+
note over develop: 1.3.0.0-unstable
22+
develop -> featureAbc: branch
23+
note over featureAbc: Open Pull Request #2
24+
note over featureAbc: 1.3.0-PullRequest.2+0
25+
featureAbc -> featureAbc: commit
26+
note over featureAbc: 1.3.0-PullRequest.2+1
27+
featureAbc -> develop: merge --no-ff
28+
note over develop: 1.3.0.3-unstable
29+
develop -> release-1.3.0: branch
30+
note over release-1.3.0: 1.3.0-beta.1+0
31+
develop -> develop: commit
32+
note over develop: 1.3.0.4-unstable
33+
release-1.3.0 -> release-1.3.0: commit
34+
note over release-1.3.0: 1.3.0-beta.1+1
35+
release-1.3.0 -> release-1.3.0: tag 1.3.0-beta.1
36+
note over release-1.3.0: 1.3.0-beta.2+1
37+
release-1.3.0 -> master: merge and tag master 1.3.0
38+
note over master: 1.3.0
39+
release-1.3.0 -> develop: merge --no-ff
40+
note over develop: 1.4.0.2-unstable
41+
*/
42+
[Fact]
43+
public void MinorReleaseExample()
44+
{
45+
using (var fixture = new EmptyRepositoryFixture())
46+
{
47+
fixture.Repository.MakeATaggedCommit("1.2.0");
48+
49+
// Branch to develop
50+
fixture.Repository.CreateBranch("develop").Checkout();
51+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0.0-unstable");
52+
53+
// Open Pull Request
54+
fixture.Repository.CreateBranch("pull/2/merge").Checkout();
55+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-PullRequest.2+0");
56+
fixture.Repository.MakeACommit();
57+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-PullRequest.2+1");
58+
59+
// Merge into develop
60+
fixture.Repository.Checkout("develop");
61+
fixture.Repository.MergeNoFF("pull/2/merge", Constants.SignatureNow());
62+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0.3-unstable");
63+
64+
// Create release branch
65+
fixture.Repository.CreateBranch("release-1.3.0").Checkout();
66+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+0");
67+
68+
// Make another commit on develop
69+
fixture.Repository.Checkout("develop");
70+
fixture.Repository.MakeACommit();
71+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0.4-unstable");
72+
73+
// Make a commit to release-1.3.0
74+
fixture.Repository.Checkout("release-1.3.0");
75+
fixture.Repository.MakeACommit();
76+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.1+1");
77+
78+
// Apply beta.0 tag
79+
fixture.Repository.ApplyTag("1.3.0-beta.1");
80+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0-beta.2+1");
81+
82+
// Merge release branch to master
83+
fixture.Repository.Checkout("master");
84+
// No way to force a merge commit in libgit2, so commit before merge
85+
fixture.Repository.MakeACommit();
86+
fixture.Repository.MergeNoFF("release-1.3.0", Constants.SignatureNow());
87+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.3.0");
88+
fixture.Repository.ApplyTag("1.3.0");
89+
90+
// Verify develop version
91+
fixture.Repository.Checkout("develop");
92+
fixture.Repository.MergeNoFF("release-1.3.0", Constants.SignatureNow());
93+
fixture.ExecuteGitVersion().OutputVariables[VariableProvider.FullSemVer].ShouldBe("1.4.0.3-unstable");
94+
}
95+
}
96+
}
97+
}

AcceptanceTests/Helpers/Constants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using LibGit2Sharp;
3+
4+
public static class Constants
5+
{
6+
public static Signature SignatureNow()
7+
{
8+
return new Signature("A. U. Thor", "[email protected]", DateTimeOffset.Now);
9+
}
10+
}

AcceptanceTests/Helpers/GitHelper.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@
55

66
namespace GitHubFlowVersion.AcceptanceTests.Helpers
77
{
8+
using GitVersion;
9+
810
public static class GitHelper
911
{
1012
public static Commit MakeACommit(this IRepository repository)
1113
{
1214
var randomFile = Path.Combine(repository.Info.WorkingDirectory, Guid.NewGuid().ToString());
1315
File.WriteAllText(randomFile, string.Empty);
1416
repository.Index.Stage(randomFile);
15-
return repository.Commit("Test Commit", new Signature("Test User", "[email protected]", DateTimeOffset.UtcNow));
17+
return repository.Commit("Test Commit", Constants.SignatureNow());
18+
}
19+
public static void MergeNoFF(this IRepository repository, string branch, Signature sig)
20+
{
21+
repository.MakeACommit();
22+
repository.Merge(repository.FindBranch(branch).Tip, sig);
23+
repository.Commit(string.Format("Merge branch '{0}'", branch), amendPreviousCommit: true);
1624
}
1725

1826
public static Commit[] MakeCommits(this IRepository repository, int numCommitsToMake)

GitVersion/GitFlow/BranchFinders/DevelopVersionFinder.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace GitVersion
22
{
33
using System.Linq;
4+
using LibGit2Sharp;
45

56
class DevelopVersionFinder
67
{
@@ -10,11 +11,14 @@ public SemanticVersion FindVersion(GitVersionContext context)
1011
var tip = context.CurrentBranch.Tip;
1112
var versionFromMaster = versionOnMasterFinder.Execute(context, tip.When());
1213

13-
var developBranch = context.Repository.FindBranch("develop");
14-
var numberOfCommitsSinceRelease = developBranch.Commits
15-
.SkipWhile(x => x != tip)
16-
.TakeWhile(x => x.When() >= versionFromMaster.Timestamp)
17-
.Count();
14+
var f = new CommitFilter
15+
{
16+
Since = tip,
17+
Until = context.Repository.FindBranch("master").Tip
18+
};
19+
20+
var c = context.Repository.Commits.QueryBy(f);
21+
var numberOfCommitsSinceRelease = c.Count();
1822

1923
var releaseDate = ReleaseDateFinder.Execute(context.Repository, tip.Sha, 0);
2024
var semanticVersion = new SemanticVersion

GitVersion/GitFlow/BranchFinders/OptionallyTaggedBranchVersionFinderBase.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected SemanticVersion FindVersion(
2222
if (branchType == BranchType.Hotfix)
2323
version.PreReleaseTag = "hotfix0";
2424
if (branchType == BranchType.Release)
25-
version.PreReleaseTag = "beta0";
25+
version.PreReleaseTag = "beta1";
2626

2727
var tagVersion = RetrieveMostRecentOptionalTagVersion(context.Repository, version, context.CurrentBranch.Commits.Take(nbHotfixCommits + 1));
2828

@@ -41,13 +41,14 @@ protected SemanticVersion FindVersion(
4141

4242
if (tagVersion != null)
4343
{
44+
tagVersion.PreReleaseTag.Number++;
4445
semanticVersion.PreReleaseTag = tagVersion.PreReleaseTag;
4546
}
4647

4748
return semanticVersion;
4849
}
4950

50-
bool IsMostRecentCommitTagged(GitVersionContext context)
51+
bool IsMostRecentCommitTagged(GitVersionContext context, out SemanticVersion version)
5152
{
5253
var currentCommit = context.CurrentBranch.Commits.First();
5354

@@ -57,13 +58,13 @@ bool IsMostRecentCommitTagged(GitVersionContext context)
5758

5859
foreach (var tag in tags)
5960
{
60-
SemanticVersion version;
6161
if (SemanticVersion.TryParse(tag.Name, out version))
6262
{
6363
return true;
6464
}
6565
}
6666

67+
version = null;
6768
return false;
6869
}
6970

GitVersion/GitVersion.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<Compile Include="BuildServers\GitHelper.cs" />
7777
<Compile Include="BuildServers\IBuildServer.cs" />
7878
<Compile Include="BuildServers\TeamCity.cs" />
79+
<Compile Include="OutputVariables\CiFeedFormatter.cs" />
7980
<Compile Include="OutputVariables\VariableProvider.cs" />
8081
<Compile Include="GitVersionContext.cs" />
8182
<Compile Include="HelpWriter.cs" />
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
5+
public class CiFeedFormatter : IFormatProvider, ICustomFormatter
6+
{
7+
public object GetFormat(Type formatType)
8+
{
9+
if (formatType == typeof(SemanticVersion))
10+
return this;
11+
12+
return null;
13+
}
14+
15+
public string Format(string format, object arg, IFormatProvider formatProvider)
16+
{
17+
var semanticVersion = (SemanticVersion) arg;
18+
19+
switch (format)
20+
{
21+
case "s":
22+
case "sp":
23+
case "f":
24+
case "fp":
25+
return string.Format("{0}.{1}{2}", semanticVersion.ToString("j"),
26+
semanticVersion.BuildMetaData.CommitsSinceTag ?? 0,
27+
semanticVersion.PreReleaseTag.HasTag() ? "-" + semanticVersion.PreReleaseTag.Name: null);
28+
default:
29+
return semanticVersion.ToString(format);
30+
}
31+
}
32+
}
33+
}

GitVersion/OutputVariables/VariableProvider.cs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public static Dictionary<string, string> GetVariablesFor(SemanticVersion semanti
4141
{SemVer, semanticVersion.ToString(null, formatter)},
4242
{SemVerPadded, semanticVersion.ToString("sp", formatter)},
4343
{AssemblySemVer, semanticVersion.ToString("j") + ".0"},
44-
{FullSemVer, semanticVersion.ToString("f")},
44+
{FullSemVer, semanticVersion.ToString("f", formatter)},
4545
{FullSemVerPadded, semanticVersion.ToString("fp", formatter)},
4646
{InformationalVersion, semanticVersion.ToString("i", formatter)},
4747
{ClassicVersion, string.Format("{0}.{1}", semanticVersion.ToString("j"), (semanticVersion.BuildMetaData.CommitsSinceTag ?? 0))},
@@ -55,31 +55,4 @@ public static Dictionary<string, string> GetVariablesFor(SemanticVersion semanti
5555
return variables;
5656
}
5757
}
58-
59-
public class CiFeedFormatter : IFormatProvider, ICustomFormatter
60-
{
61-
public object GetFormat(Type formatType)
62-
{
63-
if (formatType == typeof(SemanticVersion))
64-
return this;
65-
66-
return null;
67-
}
68-
69-
public string Format(string format, object arg, IFormatProvider formatProvider)
70-
{
71-
var semanticVersion = (SemanticVersion) arg;
72-
73-
switch (format)
74-
{
75-
case "s":
76-
case "sp":
77-
return string.Format("{0}.{1}{2}", semanticVersion.ToString("j"),
78-
semanticVersion.BuildMetaData.CommitsSinceTag ?? 0,
79-
semanticVersion.PreReleaseTag.HasTag() ? "-" + semanticVersion.PreReleaseTag.Name: null);
80-
default:
81-
return semanticVersion.ToString(format);
82-
}
83-
}
84-
}
8558
}

GitVersion/SemanticVersionPreReleaseTag.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ namespace GitVersion
55

66
public class SemanticVersionPreReleaseTag : IFormattable, IComparable<SemanticVersionPreReleaseTag>
77
{
8+
public string Name;
9+
public int? Number;
810

911
public SemanticVersionPreReleaseTag()
1012
{
@@ -16,10 +18,6 @@ public SemanticVersionPreReleaseTag(string name, int? number)
1618
Number = number;
1719
}
1820

19-
public readonly string Name;
20-
21-
public readonly int? Number;
22-
2321
protected bool Equals(SemanticVersionPreReleaseTag other)
2422
{
2523
return string.Equals(Name, other.Name) && Number == other.Number;
@@ -42,14 +40,6 @@ public override bool Equals(object obj)
4240
return Equals((SemanticVersionPreReleaseTag) obj);
4341
}
4442

45-
public override int GetHashCode()
46-
{
47-
unchecked
48-
{
49-
return ((Name != null ? Name.GetHashCode() : 0)*397) ^ Number.GetHashCode();
50-
}
51-
}
52-
5343
public static bool operator ==(SemanticVersionPreReleaseTag left, SemanticVersionPreReleaseTag right)
5444
{
5545
return Equals(left, right);

0 commit comments

Comments
 (0)