Skip to content

Commit b8c34c3

Browse files
DanielRoseJakeGinnivan
authored andcommitted
Add comments.
1 parent 1fe37c3 commit b8c34c3

11 files changed

+71
-10
lines changed

src/GitVersionCore/Configuration/BranchConfig.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ public BranchConfig()
88
{
99
}
1010

11+
/// <summary>
12+
/// Creates a clone of the given <paramref name="branchConfiguration"/>.
13+
/// </summary>
1114
public BranchConfig(BranchConfig branchConfiguration)
1215
{
13-
Regex = branchConfiguration.Regex;
1416
VersioningMode = branchConfiguration.VersioningMode;
1517
Tag = branchConfiguration.Tag;
1618
Increment = branchConfiguration.Increment;
@@ -19,6 +21,7 @@ public BranchConfig(BranchConfig branchConfiguration)
1921
TrackMergeTarget = branchConfiguration.TrackMergeTarget;
2022
CommitMessageIncrementing = branchConfiguration.CommitMessageIncrementing;
2123
TracksReleaseBranches = branchConfiguration.TracksReleaseBranches;
24+
Regex = branchConfiguration.Regex;
2225
IsReleaseBranch = branchConfiguration.IsReleaseBranch;
2326
IsMainline = branchConfiguration.IsMainline;
2427
}

src/GitVersionCore/Configuration/IncrementStrategy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public enum IncrementStrategy
99
Minor,
1010
Patch,
1111
/// <summary>
12-
/// Uses the increment strategy from the branch the current branch was branched from
12+
/// Uses the <see cref="BranchConfig.Increment"/>, <see cref="BranchConfig.PreventIncrementOfMergedBranchVersion"/> and <see cref="BranchConfig.IsDevelop"/>
13+
/// of the "parent" branch (i.e. the branch where the current branch was branched from).
1314
/// </summary>
1415
Inherit
1516
}

src/GitVersionCore/IncrementStrategyFinder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static class IncrementStrategyFinder
3838
commitMessageIncrement = VersionField.Minor;
3939
}
4040

41-
// don't increment for less than the branch config increment, if the absense of commit messages would have
41+
// don't increment for less than the branch config increment, if the absence of commit messages would have
4242
// still resulted in an increment of configuration.Increment
4343
if (baseVersion.ShouldIncrement && commitMessageIncrement < defaultIncrement)
4444
{
@@ -54,7 +54,7 @@ public static class IncrementStrategyFinder
5454
{
5555
return null;
5656
}
57-
57+
5858
var commits = GetIntermediateCommits(context.Repository, baseVersion.BaseVersionSource, context.CurrentCommit);
5959

6060
if (context.Configuration.CommitMessageIncrementing == CommitMessageIncrementMode.MergeMessageOnly)

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public static IEnumerable<SemanticVersion> GetVersionTagsOnBranch(this Branch br
3232
}));
3333
}
3434

35-
35+
/// <summary>
36+
/// Find the commit where the given branch was branched from another branch.
37+
/// If there are multiple such commits and branches, returns the newest commit.
38+
/// </summary>
3639
public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branch, IRepository repository, params Branch[] excludedBranches)
3740
{
3841
const string missingTipFormat = "{0} has no tip. Please see http://example.com/docs for information on how to fix this.";
@@ -79,6 +82,9 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
7982
}
8083
}
8184

85+
/// <summary>
86+
/// Find the merge base of the two branches, i.e. the best common ancestor of the two branches' tips.
87+
/// </summary>
8288
public static Commit FindMergeBase(this Branch branch, Branch otherBranch, IRepository repository)
8389
{
8490
using (Logger.IndentLog(string.Format("Finding merge base between '{0}' and {1}.", branch.FriendlyName, otherBranch.FriendlyName)))
@@ -96,15 +102,15 @@ public static Commit FindMergeBase(this Branch branch, Branch otherBranch, IRepo
96102
{
97103
Logger.WriteInfo(string.Format("Found merge base of {0}", findMergeBase.Sha));
98104
// We do not want to include merge base commits which got forward merged into the other branch
99-
bool mergeBaseWasFowardMerge;
105+
bool mergeBaseWasForwardMerge;
100106
do
101107
{
102108
// Now make sure that the merge base is not a forward merge
103-
mergeBaseWasFowardMerge = otherBranch.Commits
109+
mergeBaseWasForwardMerge = otherBranch.Commits
104110
.SkipWhile(c => c != commitToFindCommonBase)
105111
.TakeWhile(c => c != findMergeBase)
106112
.Any(c => c.Parents.Contains(findMergeBase));
107-
if (mergeBaseWasFowardMerge)
113+
if (mergeBaseWasForwardMerge)
108114
{
109115
var second = commitToFindCommonBase.Parents.First();
110116
var mergeBase = repository.ObjectDatabase.FindMergeBase(commit, second);
@@ -115,7 +121,7 @@ public static Commit FindMergeBase(this Branch branch, Branch otherBranch, IRepo
115121
findMergeBase = mergeBase;
116122
Logger.WriteInfo(string.Format("Merge base was due to a forward merge, next merge base is {0}", findMergeBase));
117123
}
118-
} while (mergeBaseWasFowardMerge);
124+
} while (mergeBaseWasForwardMerge);
119125
}
120126
return findMergeBase;
121127
}

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
{
33
using System.Collections.Generic;
44

5+
/// <summary>
6+
/// Version is from NextVersion (the configuration value), unless the current commit is tagged.
7+
/// BaseVersionSource is null.
8+
/// Does not increment.
9+
/// </summary>
510
public class ConfigNextVersionBaseVersionStrategy : BaseVersionStrategy
611
{
712
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
using System.Text.RegularExpressions;
77
using LibGit2Sharp;
88

9+
/// <summary>
10+
/// Version is extracted from older commits's merge messages.
11+
/// BaseVersionSource is the commit where the message was found.
12+
/// Increments if PreventIncrementForMergedBranchVersion (from the branch config) is false.
13+
/// </summary>
914
public class MergeMessageBaseVersionStrategy : BaseVersionStrategy
1015
{
1116
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
using System.Linq;
66
using LibGit2Sharp;
77

8+
/// <summary>
9+
/// Version is extracted from all tags on the branch which are valid, and not newer than the current commit.
10+
/// BaseVersionSource is the tag's commit.
11+
/// Increments if the tag is not the current commit.
12+
/// </summary>
813
public class TaggedCommitVersionStrategy : BaseVersionStrategy
914
{
1015
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
using System.Collections.Generic;
55
using LibGit2Sharp;
66

7+
/// <summary>
8+
/// Version is extracted from the name of the branch.
9+
/// BaseVersionSource is the commit where the branch was branched from its parent.
10+
/// Does not increment.
11+
/// </summary>
712
public class VersionInBranchBaseVersionStrategy : BaseVersionStrategy
813
{
914
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)

src/GitVersionCore/VersionCalculation/BaseVersionStrategy.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55

66
public abstract class BaseVersionStrategy
77
{
8+
/// <summary>
9+
/// Calculates the <see cref="BaseVersion"/> values for the given <paramref name="context"/>.
10+
/// </summary>
11+
/// <param name="context">
12+
/// The context for calculating the <see cref="BaseVersion"/>.
13+
/// </param>
14+
/// <returns>
15+
/// An <see cref="IEnumerable{BaseVersion}"/> of the base version values found by the strategy.
16+
/// </returns>
817
public abstract IEnumerable<BaseVersion> GetVersions(GitVersionContext context);
918
}
1019
}

src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@ namespace GitVersion.VersionCalculation
88
using LibGit2Sharp;
99

1010
/// <summary>
11-
/// Inherit version from release branch and tags on master
11+
/// Active only when the branch is marked as IsDevelop.
12+
/// Two different algorithms (results are merged):
13+
/// <para>
14+
/// Using <see cref="VersionInBranchBaseVersionStrategy"/>:
15+
/// Version is that of any child branches marked with IsReleaseBranch (except if they have no commits of their own).
16+
/// BaseVersionSource is the commit where the child branch was created.
17+
/// Always increments.
18+
/// </para>
19+
/// <para>
20+
/// Using <see cref="TaggedCommitVersionStrategy"/>:
21+
/// Version is extracted from all tags on the <c>master</c> branch which are valid.
22+
/// BaseVersionSource is the tag's commit (same as base strategy).
23+
/// Increments if the tag is not the current commit (same as base strategy).
24+
/// </para>
1225
/// </summary>
1326
public class TrackReleaseBranchesVersionStrategy : BaseVersionStrategy
1427
{
@@ -70,9 +83,13 @@ IEnumerable<BaseVersion> GetReleaseVersion(GitVersionContext context, Branch rel
7083
var tagPrefixRegex = context.Configuration.GitTagPrefix;
7184
var repository = context.Repository;
7285

86+
// Find the commit where the child branch was created.
7387
var baseSource = releaseBranch.FindMergeBase(context.CurrentBranch, repository);
7488
if (baseSource == context.CurrentCommit)
89+
{
90+
// Ignore the branch if it has no commits.
7591
return new BaseVersion[0];
92+
}
7693

7794
return releaseVersionStrategy
7895
.GetVersions(context, tagPrefixRegex, releaseBranch, repository)

src/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
using BaseVersionCalculators;
66
using LibGit2Sharp;
77

8+
/// <summary>
9+
/// Version is 0.1.0.
10+
/// BaseVersionSource is the "root" commit reachable from the current commit.
11+
/// Does not increment.
12+
/// </summary>
813
public class FallbackBaseVersionStrategy : BaseVersionStrategy
914
{
1015
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)

0 commit comments

Comments
 (0)