Skip to content

Commit 2607b9d

Browse files
committed
Created complete GitFlow example
1 parent bf558c1 commit 2607b9d

File tree

6 files changed

+368
-108
lines changed

6 files changed

+368
-108
lines changed
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# GitFlow Examples
2-
## Continuous Delivery mode
3-
TODO Example of GitFlow using continuous delivery mode
42

5-
## Continuous Deployment mode
6-
TODO Example of GitFlow using continuous deployment mode
3+
![GitFlow](http://uml.mvnsearch.org/gist/cf053d7f5d336ae9f7bb)
4+
5+
## Source
6+
7+
See `DocumentationSamples.GitFlowExample`. To update, modify then run test. Update [https://gist.github.com/JakeGinnivan/cf053d7f5d336ae9f7bb](https://gist.github.com/JakeGinnivan/cf053d7f5d336ae9f7bb)

src/GitVersionCore.Tests/Fixtures/RepositoryFixtureBase.cs

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Diagnostics;
4+
using System.Text;
35
using GitVersion;
46
using LibGit2Sharp;
57
using Shouldly;
68

79
public abstract class RepositoryFixtureBase : IDisposable
810
{
11+
Dictionary<string, string> participants = new Dictionary<string, string>();
912
public string RepositoryPath;
1013
public IRepository Repository;
11-
private Config configuration;
14+
Config configuration;
15+
StringBuilder diagramBuilder;
1216

1317
protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder, Config configuration)
1418
{
19+
diagramBuilder = new StringBuilder();
20+
diagramBuilder.AppendLine("@startuml");
1521
this.configuration = configuration;
1622
RepositoryPath = PathHelper.GetTempPath();
1723
Repository = repoBuilder(RepositoryPath);
@@ -22,15 +28,118 @@ protected RepositoryFixtureBase(Func<string, IRepository> repoBuilder, Config co
2228

2329
public bool IsForTrackedBranchOnly { private get; set; }
2430

31+
public void Checkout(string branch)
32+
{
33+
Repository.Checkout(branch);
34+
}
35+
36+
public void Activate(string branch)
37+
{
38+
diagramBuilder.AppendLineFormat("activate {0}", GetParticipant(branch));
39+
}
40+
41+
public void Destroy(string branch)
42+
{
43+
diagramBuilder.AppendLineFormat("destroy {0}", GetParticipant(branch));
44+
}
45+
46+
public void Participant(string participant, string @as = null)
47+
{
48+
participants.Add(participant, @as ?? participant);
49+
if (@as == null)
50+
diagramBuilder.AppendLineFormat("participant {0}", participant);
51+
else
52+
diagramBuilder.AppendLineFormat("participant \"{0}\" as {1}", participant, @as);
53+
}
54+
55+
public void Divider(string text)
56+
{
57+
diagramBuilder.AppendLineFormat("== {0} ==", text);
58+
}
59+
60+
public void NoteOver(string noteText, string startNode, string endNode = null, string prefix = null)
61+
{
62+
diagramBuilder.AppendLineFormat(
63+
prefix + @"note over {0}{1}
64+
{2}
65+
end note",
66+
GetParticipant(startNode),
67+
endNode == null ? null : ", " + GetParticipant(endNode),
68+
noteText.Replace("\n", "\n "));
69+
}
70+
71+
public void MakeATaggedCommit(string tag)
72+
{
73+
MakeACommit();
74+
ApplyTag(tag);
75+
}
76+
77+
public void ApplyTag(string tag)
78+
{
79+
diagramBuilder.AppendLineFormat("{0} -> {0}: tag {1}", GetParticipant(Repository.Head.Name), tag);
80+
Repository.ApplyTag(tag);
81+
}
82+
83+
public void BranchTo(string branchName, string @as = null)
84+
{
85+
if (!participants.ContainsKey(branchName))
86+
{
87+
diagramBuilder.Append("create ");
88+
Participant(branchName, @as);
89+
}
90+
else
91+
{
92+
NoteOver(branchName, branchName, prefix: "h");
93+
}
94+
95+
var branch = Repository.Head.Name;
96+
diagramBuilder.AppendLineFormat("{0} -> {1}: branch from {2}", GetParticipant(branch), GetParticipant(branchName), branch);
97+
Repository.CreateBranch(branchName).Checkout();
98+
}
99+
100+
public void BranchToFromTag(string branchName, string fromTag, string onBranch, string @as = null)
101+
{
102+
if (!participants.ContainsKey(branchName))
103+
{
104+
diagramBuilder.Append("create ");
105+
Participant(branchName, @as);
106+
}
107+
108+
diagramBuilder.AppendLineFormat("{0} -> {1}: branch from tag ({2})", GetParticipant(onBranch), GetParticipant(branchName), fromTag);
109+
Repository.CreateBranch(branchName).Checkout();
110+
}
111+
112+
public void MakeACommit()
113+
{
114+
diagramBuilder.AppendLineFormat("{0} -> {0}: commit", GetParticipant(Repository.Head.Name));
115+
Repository.MakeACommit();
116+
}
117+
118+
public void MergeNoFF(string mergeTarget)
119+
{
120+
diagramBuilder.AppendLineFormat("{0} -> {1}: merge", GetParticipant(mergeTarget), GetParticipant(Repository.Head.Name));
121+
Repository.MergeNoFF(mergeTarget, Constants.SignatureNow());
122+
}
123+
25124
public void AssertFullSemver(string fullSemver, IRepository repository = null, string commitId = null)
26125
{
27126
Trace.WriteLine("---------");
28127

29128
var variables = GetVersion(repository, commitId);
30129
variables.FullSemVer.ShouldBe(fullSemver);
130+
if (commitId == null)
131+
diagramBuilder.AppendLineFormat("note over {0} #D3D3D3: {1}", GetParticipant(Repository.Head.Name), fullSemver);
132+
}
133+
134+
string GetParticipant(string branch)
135+
{
136+
if (participants.ContainsKey(branch))
137+
return participants[branch];
138+
139+
return branch;
31140
}
32141

33-
public VersionVariables GetVersion(IRepository repository = null, string commitId = null)
142+
VersionVariables GetVersion(IRepository repository = null, string commitId = null)
34143
{
35144
var gitVersionContext = new GitVersionContext(repository ?? Repository, configuration, IsForTrackedBranchOnly, commitId);
36145
var executeGitVersion = ExecuteGitVersion(gitVersionContext);
@@ -51,7 +160,7 @@ public VersionVariables GetVersion(IRepository repository = null, string commitI
51160
}
52161
}
53162

54-
private SemanticVersion ExecuteGitVersion(GitVersionContext context)
163+
SemanticVersion ExecuteGitVersion(GitVersionContext context)
55164
{
56165
var vf = new GitVersionFinder();
57166
return vf.FindVersion(context);
@@ -67,7 +176,12 @@ public virtual void Dispose()
67176
}
68177
catch (Exception e)
69178
{
70-
Console.WriteLine("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message);
179+
Trace.WriteLine(string.Format("Failed to clean up repository path at {0}. Received exception: {1}", RepositoryPath, e.Message));
71180
}
181+
182+
diagramBuilder.AppendLine("@enduml");
183+
Trace.WriteLine("**Visualisation of test:**");
184+
Trace.WriteLine(string.Empty);
185+
Trace.WriteLine(diagramBuilder.ToString());
72186
}
73187
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
<Compile Include="IntegrationTests\ReleaseBranchScenarios.cs" />
9696
<Compile Include="IntegrationTests\SwitchingToGitFlowScenarios.cs" />
9797
<Compile Include="IntegrationTests\VersionBumpingScenarios.cs" />
98-
<Compile Include="IntegrationTests\UncycloScenarios.cs" />
98+
<Compile Include="IntegrationTests\DocumentationSamples.cs" />
9999
<Compile Include="IntegrationTests\OtherBranchScenarios.cs" />
100100
<Compile Include="Helpers\Constants.cs" />
101101
<Compile Include="InformationalVersionBuilderTests.cs" />

0 commit comments

Comments
 (0)