Skip to content

Commit 9eb8711

Browse files
authored
Merge pull request #1037 from JakeGinnivan/AddDiagSwitch
Add diag switch
2 parents 8fba288 + f199f09 commit 9eb8711

16 files changed

+66
-29
lines changed

src/GitVersionCore.Tests/VersionCalculation/BaseVersionCalculatorTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public V1Strategy(DateTimeOffset? when)
6767

6868
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
6969
{
70-
yield return new BaseVersion("Source 1", false, new SemanticVersion(1), when, null);
70+
yield return new BaseVersion(context, "Source 1", false, new SemanticVersion(1), when, null);
7171
}
7272
}
7373

@@ -82,7 +82,7 @@ public V2Strategy(DateTimeOffset? when)
8282

8383
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
8484
{
85-
yield return new BaseVersion("Source 2", true, new SemanticVersion(2), when, null);
85+
yield return new BaseVersion(context, "Source 2", true, new SemanticVersion(2), when, null);
8686
}
8787
}
8888

@@ -91,7 +91,7 @@ public void ShouldNotFilterVersion()
9191
{
9292
var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude());
9393
var context = new GitVersionContextBuilder().WithConfig(new Config() { Ignore = fakeIgnoreConfig }).Build();
94-
var version = new BaseVersion("dummy", false, new SemanticVersion(2), new MockCommit(), null);
94+
var version = new BaseVersion(context, "dummy", false, new SemanticVersion(2), new MockCommit(), null);
9595
var sut = new BaseVersionCalculator(new TestVersionStrategy(version));
9696

9797
var baseVersion = sut.GetBaseVersion(context);
@@ -106,8 +106,8 @@ public void ShouldFilterVersion()
106106
{
107107
var fakeIgnoreConfig = new TestIgnoreConfig(new ExcludeSourcesContainingExclude());
108108
var context = new GitVersionContextBuilder().WithConfig(new Config() { Ignore = fakeIgnoreConfig }).Build();
109-
var higherVersion = new BaseVersion("exclude", false, new SemanticVersion(2), new MockCommit(), null);
110-
var lowerVersion = new BaseVersion("dummy", false, new SemanticVersion(1), new MockCommit(), null);
109+
var higherVersion = new BaseVersion(context, "exclude", false, new SemanticVersion(2), new MockCommit(), null);
110+
var lowerVersion = new BaseVersion(context, "dummy", false, new SemanticVersion(1), new MockCommit(), null);
111111
var sut = new BaseVersionCalculator(new TestVersionStrategy(higherVersion, lowerVersion));
112112

113113
var baseVersion = sut.GetBaseVersion(context);

src/GitVersionCore.Tests/VersionCalculation/TestBaseVersionCalculator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public TestBaseVersionCalculator(bool shouldIncrement, SemanticVersion semanticV
2020

2121
public BaseVersion GetBaseVersion(GitVersionContext context)
2222
{
23-
return new BaseVersion("Test source", shouldIncrement, semanticVersion, source, null);
23+
return new BaseVersion(context, "Test source", shouldIncrement, semanticVersion, source, null);
2424
}
2525
}
2626
}

src/GitVersionCore.Tests/VersionFilters/MinDateVersionFilterTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ public void VerifyNullGuard()
2323
[Test]
2424
public void WhenCommitShouldExcludeWithReason()
2525
{
26+
var context = new GitVersionContextBuilder().Build();
2627
var commit = new MockCommit(); //when = UtcNow
27-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
28+
var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
2829
var futureDate = DateTimeOffset.UtcNow.AddYears(1);
2930
var sut = new MinDateVersionFilter(futureDate);
3031

@@ -37,7 +38,8 @@ public void WhenCommitShouldExcludeWithReason()
3738
public void WhenShaMismatchShouldNotExclude()
3839
{
3940
var commit = new MockCommit(); //when = UtcNow
40-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
41+
var context = new GitVersionContextBuilder().Build();
42+
var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
4143
var pastDate = DateTimeOffset.UtcNow.AddYears(-1);
4244
var sut = new MinDateVersionFilter(pastDate);
4345

@@ -49,7 +51,8 @@ public void WhenShaMismatchShouldNotExclude()
4951
[Test]
5052
public void ExcludeShouldAcceptVersionWithNullCommit()
5153
{
52-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
54+
var context = new GitVersionContextBuilder().Build();
55+
var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), null, string.Empty);
5356
var futureDate = DateTimeOffset.UtcNow.AddYears(1);
5457
var sut = new MinDateVersionFilter(futureDate);
5558

src/GitVersionCore.Tests/VersionFilters/ShaVersionFilterTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public void VerifyNullGuard2()
3030
public void WhenShaMatchShouldExcludeWithReason()
3131
{
3232
var commit = new MockCommit();
33-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
33+
var context = new GitVersionContextBuilder().Build();
34+
var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
3435
var sut = new ShaVersionFilter(new[] { commit.Sha });
3536

3637
string reason;
@@ -42,7 +43,8 @@ public void WhenShaMatchShouldExcludeWithReason()
4243
public void WhenShaMismatchShouldNotExclude()
4344
{
4445
var commit = new MockCommit();
45-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), commit, string.Empty);
46+
var context = new GitVersionContextBuilder().Build();
47+
var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), commit, string.Empty);
4648
var sut = new ShaVersionFilter(new[] { "mismatched" });
4749

4850
string reason;
@@ -53,7 +55,8 @@ public void WhenShaMismatchShouldNotExclude()
5355
[Test]
5456
public void ExcludeShouldAcceptVersionWithNullCommit()
5557
{
56-
var version = new BaseVersion("dummy", false, new SemanticVersion(1), null, string.Empty);
58+
var context = new GitVersionContextBuilder().Build();
59+
var version = new BaseVersion(context, "dummy", false, new SemanticVersion(1), null, string.Empty);
5760
var sut = new ShaVersionFilter(new[] { "mismatched" });
5861

5962
string reason;

src/GitVersionCore/VersionCalculation/BaseVersionCalculator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public BaseVersion GetBaseVersion(GitVersionContext context)
7171
throw new Exception("Base version should not be null");
7272

7373
var calculatedBase = new BaseVersion(
74-
maxVersion.Version.Source, maxVersion.Version.ShouldIncrement, maxVersion.Version.SemanticVersion,
74+
context, maxVersion.Version.Source, maxVersion.Version.ShouldIncrement, maxVersion.Version.SemanticVersion,
7575
baseVersionWithOldestSource.BaseVersionSource, maxVersion.Version.BranchNameOverride);
7676

7777
Logger.WriteInfo(string.Format("Base version used: {0}", calculatedBase));
@@ -80,7 +80,7 @@ public BaseVersion GetBaseVersion(GitVersionContext context)
8080
}
8181
}
8282

83-
static SemanticVersion MaybeIncrement(GitVersionContext context, BaseVersion version)
83+
public static SemanticVersion MaybeIncrement(GitVersionContext context, BaseVersion version)
8484
{
8585
var increment = IncrementStrategyFinder.DetermineIncrementedField(context, version);
8686
if (increment != null)

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/BaseVersion.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44

55
public class BaseVersion
66
{
7-
public BaseVersion(string source, bool shouldIncrement, SemanticVersion semanticVersion, Commit baseVersionSource, string branchNameOverride)
7+
GitVersionContext _context;
8+
9+
public BaseVersion(GitVersionContext context, string source, bool shouldIncrement, SemanticVersion semanticVersion, Commit baseVersionSource, string branchNameOverride)
810
{
911
Source = source;
1012
ShouldIncrement = shouldIncrement;
1113
SemanticVersion = semanticVersion;
1214
BaseVersionSource = baseVersionSource;
1315
BranchNameOverride = branchNameOverride;
16+
_context = context;
1417
}
1518

1619
public string Source { get; private set; }
@@ -25,7 +28,11 @@ public BaseVersion(string source, bool shouldIncrement, SemanticVersion semantic
2528

2629
public override string ToString()
2730
{
28-
return string.Format("{0}: {1} with commit count source {2}", Source, SemanticVersion.ToString("f"), BaseVersionSource == null ? "External Source" : BaseVersionSource.Sha);
31+
return string.Format(
32+
"{0}: {1} with commit count source {2} (Incremented: {3})",
33+
Source, SemanticVersion.ToString("f"),
34+
BaseVersionSource == null ? "External Source" : BaseVersionSource.Sha,
35+
ShouldIncrement ? BaseVersionCalculator.MaybeIncrement(_context, this).ToString("t") : "None");
2936
}
3037
}
3138
}

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/ConfigNextVersionBaseVersionStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
99
if (string.IsNullOrEmpty(context.Configuration.NextVersion) || context.IsCurrentCommitTagged)
1010
yield break;
1111
var semanticVersion = SemanticVersion.Parse(context.Configuration.NextVersion, context.Configuration.GitTagPrefix);
12-
yield return new BaseVersion("NextVersion in GitVersion configuration file", false, semanticVersion, null, null);
12+
yield return new BaseVersion(context, "NextVersion in GitVersion configuration file", false, semanticVersion, null, null);
1313
}
1414
}
1515
}

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/MergeMessageBaseVersionStrategy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
2121
var shouldIncrement = !context.Configuration.PreventIncrementForMergedBranchVersion;
2222
return new[]
2323
{
24-
new BaseVersion(string.Format("Merge message '{0}'", c.Message.Trim()), shouldIncrement, semanticVersion, c, null)
24+
new BaseVersion(context, string.Format("Merge message '{0}'", c.Message.Trim()), shouldIncrement, semanticVersion, c, null)
2525
};
2626
}
2727
return Enumerable.Empty<BaseVersion>();
@@ -35,7 +35,7 @@ static bool TryParse(Commit mergeCommit, EffectiveConfiguration configuration, o
3535
return semanticVersion != null;
3636
}
3737

38-
private static SemanticVersion Inner(Commit mergeCommit, EffectiveConfiguration configuration)
38+
static SemanticVersion Inner(Commit mergeCommit, EffectiveConfiguration configuration)
3939
{
4040
if (mergeCommit.Parents.Count() < 2)
4141
{

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/TaggedCommitVersionStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public IEnumerable<BaseVersion> GetTaggedVersions(GitVersionContext context, Bra
4040
BaseVersion CreateBaseVersion(GitVersionContext context, VersionTaggedCommit version)
4141
{
4242
var shouldUpdateVersion = version.Commit.Sha != context.CurrentCommit.Sha;
43-
var baseVersion = new BaseVersion(FormatSource(version), shouldUpdateVersion, version.SemVer, version.Commit, null);
43+
var baseVersion = new BaseVersion(context, FormatSource(version), shouldUpdateVersion, version.SemVer, version.Commit, null);
4444
return baseVersion;
4545
}
4646

src/GitVersionCore/VersionCalculation/BaseVersionCalculators/VersionInBranchBaseVersionStrategy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
1111
var currentBranch = context.CurrentBranch;
1212
var tagPrefixRegex = context.Configuration.GitTagPrefix;
1313
var repository = context.Repository;
14-
return GetVersions(tagPrefixRegex, currentBranch, repository);
14+
return GetVersions(context, tagPrefixRegex, currentBranch, repository);
1515
}
1616

17-
public IEnumerable<BaseVersion> GetVersions(string tagPrefixRegex, Branch currentBranch, IRepository repository)
17+
public IEnumerable<BaseVersion> GetVersions(GitVersionContext context, string tagPrefixRegex, Branch currentBranch, IRepository repository)
1818
{
1919
var branchName = currentBranch.FriendlyName;
2020
var versionInBranch = GetVersionInBranch(branchName, tagPrefixRegex);
2121
if (versionInBranch != null)
2222
{
2323
var commitBranchWasBranchedFrom = currentBranch.FindCommitBranchWasBranchedFrom(repository);
2424
var branchNameOverride = branchName.RegexReplace("[-/]" + versionInBranch.Item1, string.Empty);
25-
yield return new BaseVersion("Version in branch name", false, versionInBranch.Item2, commitBranchWasBranchedFrom, branchNameOverride);
25+
yield return new BaseVersion(context, "Version in branch name", false, versionInBranch.Item2, commitBranchWasBranchedFrom, branchNameOverride);
2626
}
2727
}
2828

src/GitVersionCore/VersionCalculation/DevelopVersionStrategy.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ private IEnumerable<BaseVersion> ReleaseBranchBaseVersions(GitVersionContext con
5353
// Need to drop branch overrides and give a bit more context about
5454
// where this version came from
5555
var source1 = "Release branch exists -> " + baseVersion.Source;
56-
return new BaseVersion(source1,
56+
return new BaseVersion(context,
57+
source1,
5758
baseVersion.ShouldIncrement,
5859
baseVersion.SemanticVersion,
5960
baseVersion.BaseVersionSource,
@@ -74,8 +75,8 @@ IEnumerable<BaseVersion> GetReleaseVersion(GitVersionContext context, Branch rel
7475
return new BaseVersion[0];
7576

7677
return releaseVersionStrategy
77-
.GetVersions(tagPrefixRegex, releaseBranch, repository)
78-
.Select(b => new BaseVersion(b.Source, true, b.SemanticVersion, baseSource, b.BranchNameOverride));
78+
.GetVersions(context, tagPrefixRegex, releaseBranch, repository)
79+
.Select(b => new BaseVersion(context, b.Source, true, b.SemanticVersion, baseSource, b.BranchNameOverride));
7980
}
8081
}
8182
}

src/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
1313
{
1414
IncludeReachableFrom = context.CurrentBranch.Tip
1515
}).First(c => !c.Parents.Any());
16-
yield return new BaseVersion("Fallback base version", false, new SemanticVersion(minor: 1), baseVersionSource, null);
16+
yield return new BaseVersion(context, "Fallback base version", false, new SemanticVersion(minor: 1), baseVersionSource, null);
1717
}
1818
}
1919
}

src/GitVersionExe/ArgumentParser.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ public static Arguments ParseArguments(List<string> commandLineArguments)
150150
}
151151

152152

153+
if (name.IsSwitch("diag"))
154+
{
155+
if (value == null || value.IsTrue())
156+
{
157+
arguments.Diag = true;
158+
}
159+
continue;
160+
}
161+
162+
153163
if (name.IsSwitch("updateAssemblyInfo"))
154164
{
155165
if (value.IsTrue())

src/GitVersionExe/Arguments.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public Arguments()
2525
public string DynamicRepositoryLocation;
2626

2727
public bool Init;
28+
public bool Diag;
2829

2930
public bool IsHelp;
3031
public string LogFilePath;

src/GitVersionExe/HelpWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ GitVersion [path]
1717
1818
path The directory containing .git. If not defined current directory is used. (Must be first argument)
1919
init Configuration utility for gitversion
20+
/diag Runs GitVersion with additional diagnostic information (requires git.exe to be installed)
2021
/h or /? Shows Help
2122
2223
/targetpath Same as 'path', but not positional

src/GitVersionExe/Program.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,19 @@ static int VerifyArgumentsAndRun()
6262
HelpWriter.Write();
6363
return 0;
6464
}
65+
if (arguments.Diag)
66+
{
67+
arguments.NoCache = true;
68+
arguments.Output = OutputType.BuildServer;
69+
}
6570

6671
ConfigureLogging(arguments);
72+
73+
if (arguments.Diag)
74+
{
75+
Logger.WriteInfo("Dumping commit graph: ");
76+
GitTools.LibGitExtensions.DumpGraph(arguments.TargetPath, Logger.WriteInfo, 100);
77+
}
6778
if (!Directory.Exists(arguments.TargetPath))
6879
{
6980
Logger.WriteWarning(string.Format("The working directory '{0}' does not exist.", arguments.TargetPath));
@@ -124,7 +135,7 @@ static int VerifyArgumentsAndRun()
124135
return 0;
125136
}
126137

127-
private static void VerifyConfiguration(Arguments arguments, IFileSystem fileSystem)
138+
static void VerifyConfiguration(Arguments arguments, IFileSystem fileSystem)
128139
{
129140
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.NoFetch, arguments.TargetPath);
130141
ConfigurationProvider.Verify(gitPreparer, fileSystem);
@@ -179,7 +190,7 @@ static void ConfigureLogging(Arguments arguments)
179190

180191
static void WriteLogEntry(Arguments arguments, string s)
181192
{
182-
var contents = string.Format("{0}\t\t{1}\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), s);
193+
var contents = string.Format("{0:yyyy-MM-dd HH:mm:ss}\t\t{1}\r\n", DateTime.Now, s);
183194
File.AppendAllText(arguments.LogFilePath, contents);
184195
}
185196

0 commit comments

Comments
 (0)