Skip to content

Commit 499ba45

Browse files
committed
replace Logger with ILog
1 parent 0670410 commit 499ba45

19 files changed

+122
-109
lines changed

src/GitVersionCore.Tests/DynamicRepositoryTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace GitVersionCore.Tests
99
{
1010
[TestFixture]
11+
[Ignore("These tests are slow and fail on the second run in Test Explorer and need to be re-written")]
1112
public class DynamicRepositoryTests : TestBase
1213
{
1314
string workDirectory;
@@ -36,7 +37,6 @@ public void Cleanup()
3637
}
3738

3839
// Note: use same name twice to see if changing commits works on same (cached) repository
39-
[Ignore("These tests are slow and fail on the second run in Test Explorer and need to be re-written")]
4040
[NonParallelizable]
4141
[TestCase("GV_master", "https://github.com/GitTools/GitVersion", "master", "4783d325521463cd6cf1b61074352da84451f25d", "4.0.0+1086")]
4242
[TestCase("GV_master", "https://github.com/GitTools/GitVersion", "master", "3bdcd899530b4e9b37d13639f317da04a749e728", "4.0.0+1092")]

src/GitVersionCore.Tests/ExecuteCoreTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public void CacheKeySameAfterReNormalizing()
4545
var gitPreparer = new GitPreparer(log, targetUrl, null, new Authentication(), false, fixture.RepositoryPath);
4646
var configFileLocator = new DefaultConfigFileLocator();
4747
gitPreparer.Initialise(true, targetBranch);
48-
var cacheKey1 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null, configFileLocator);
48+
var cacheKey1 = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, null, configFileLocator);
4949
gitPreparer.Initialise(true, targetBranch);
50-
var cacheKey2 = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null, configFileLocator);
50+
var cacheKey2 = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, null, configFileLocator);
5151

5252
cacheKey2.Value.ShouldBe(cacheKey1.Value);
5353
});
@@ -72,7 +72,7 @@ public void CacheKeyForWorktree()
7272
var targetUrl = "https://github.com/GitTools/GitVersion.git";
7373
var gitPreparer = new GitPreparer(log, targetUrl, null, new Authentication(), false, worktreePath);
7474
var configFileLocator = new DefaultConfigFileLocator();
75-
var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, gitPreparer, null, configFileLocator);
75+
var cacheKey = GitVersionCacheKeyFactory.Create(fileSystem, log, gitPreparer, null, configFileLocator);
7676
cacheKey.Value.ShouldNotBeEmpty();
7777
}
7878
finally

src/GitVersionCore.Tests/GitRepoMetadataProviderTests.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using NUnit.Framework;
77
using Shouldly;
88
using GitVersion.Helpers;
9+
using GitVersion.Log;
910

1011
namespace GitVersionCore.Tests
1112
{
@@ -54,10 +55,10 @@ public void FindsCorrectMergeBaseForForwardMerge()
5455

5556
var develop = fixture.Repository.FindBranch("develop");
5657
var release = fixture.Repository.FindBranch("release-2.0.0");
57-
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
58+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new NullLog(), new Config())
5859
.FindMergeBase(release, develop);
5960

60-
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
61+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new NullLog(), new Config())
6162
.FindMergeBase(develop, release);
6263

6364
fixture.Repository.DumpGraph(Console.WriteLine);
@@ -111,10 +112,10 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()
111112

112113
var develop = fixture.Repository.FindBranch("develop");
113114
var release = fixture.Repository.FindBranch("release-2.0.0");
114-
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
115+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new NullLog(), new Config())
115116
.FindMergeBase(release, develop);
116117

117-
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
118+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new NullLog(), new Config())
118119
.FindMergeBase(develop, release);
119120

120121
fixture.Repository.DumpGraph(Console.WriteLine);
@@ -186,10 +187,10 @@ public void FindsCorrectMergeBaseForMultipleForwardMerges()
186187

187188
var develop = fixture.Repository.FindBranch("develop");
188189
var release = fixture.Repository.FindBranch("release-2.0.0");
189-
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
190+
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, new NullLog(), new Config())
190191
.FindMergeBase(release, develop);
191192

192-
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new Config())
193+
var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, new NullLog(), new Config())
193194
.FindMergeBase(develop, release);
194195

195196
fixture.Repository.DumpGraph(Console.WriteLine);

src/GitVersionCore.Tests/GitToolsTestingExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
2525
configuration = new Config();
2626
ConfigurationProvider.ApplyDefaultsTo(configuration);
2727
}
28-
var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, targetBranch, configuration, isForTrackedBranchOnly, commitId);
28+
var gitVersionContext = new GitVersionContext(repository ?? fixture.Repository, new NullLog(), targetBranch, configuration, isForTrackedBranchOnly, commitId);
2929
var executeGitVersion = ExecuteGitVersion(gitVersionContext);
3030
var variables = VariableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);
3131
try

src/GitVersionCore.Tests/GitVersionContextBuilder.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using GitTools.Testing;
1+
using GitTools.Testing;
22
using GitVersion;
33
using GitVersion.Configuration;
4+
using GitVersion.Log;
45
using GitVersionCore.Tests.Mocks;
56
using LibGit2Sharp;
67

@@ -64,7 +65,7 @@ public GitVersionContext Build()
6465
var configuration = config ?? new Config();
6566
ConfigurationProvider.ApplyDefaultsTo(configuration);
6667
var repo = repository ?? CreateRepository();
67-
return new GitVersionContext(repo, repo.Head, configuration);
68+
return new GitVersionContext(repo, new NullLog(), repo.Head, configuration);
6869
}
6970

7071
IRepository CreateRepository()
@@ -83,4 +84,4 @@ IRepository CreateRepository()
8384
return mockRepository;
8485
}
8586
}
86-
}
87+
}

src/GitVersionCore.Tests/GitVersionContextTests.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
using GitTools.Testing;
1+
using GitTools.Testing;
22
using GitVersion;
33
using LibGit2Sharp;
44
using NUnit.Framework;
55
using Shouldly;
66
using System.Collections.Generic;
77
using GitVersion.Configuration;
8+
using GitVersion.Log;
89
using GitVersion.VersioningModes;
910
using GitVersionCore.Tests.Mocks;
1011

@@ -31,7 +32,7 @@ public void CanInheritVersioningMode(VersioningMode mode)
3132
}
3233
};
3334

34-
var context = new GitVersionContext(mockRepository, mockBranch, config);
35+
var context = new GitVersionContext(mockRepository, new NullLog(), mockBranch, config);
3536
context.Configuration.VersioningMode.ShouldBe(mode);
3637
}
3738

@@ -57,7 +58,7 @@ public void CanInheritIncrement(IncrementStrategy increment, IncrementStrategy?
5758
fixture.BranchTo(dummyBranchName);
5859
fixture.MakeACommit();
5960

60-
var context = new GitVersionContext(fixture.Repository, fixture.Repository.Branches[dummyBranchName], config);
61+
var context = new GitVersionContext(fixture.Repository, new NullLog(), fixture.Repository.Branches[dummyBranchName], config);
6162
context.Configuration.Increment.ShouldBe(alternateExpected ?? increment);
6263
}
6364

@@ -90,7 +91,7 @@ public void UsesBranchSpecificConfigOverTopLevelDefaults()
9091
develop
9192
}
9293
};
93-
var context = new GitVersionContext(mockRepository, develop, config);
94+
var context = new GitVersionContext(mockRepository, new NullLog(), develop, config);
9495
context.Configuration.Tag.ShouldBe("alpha");
9596
}
9697

@@ -119,10 +120,10 @@ public void UsesFirstBranchConfigWhenMultipleMatch()
119120
}
120121
};
121122

122-
var latestContext = new GitVersionContext(mockRepository, releaseLatestBranch, config);
123+
var latestContext = new GitVersionContext(mockRepository, new NullLog(), releaseLatestBranch, config);
123124
latestContext.Configuration.Increment.ShouldBe(IncrementStrategy.None);
124125

125-
var versionContext = new GitVersionContext(mockRepository, releaseVersionBranch, config);
126+
var versionContext = new GitVersionContext(mockRepository, new NullLog(), releaseVersionBranch, config);
126127
versionContext.Configuration.Increment.ShouldBe(IncrementStrategy.Patch);
127128
}
128129

@@ -147,9 +148,9 @@ public void CanFindParentBranchForInheritingIncrementStrategy()
147148
Commands.Checkout(repo.Repository, featureBranch);
148149
repo.Repository.MakeACommit();
149150

150-
var context = new GitVersionContext(repo.Repository, repo.Repository.Head, config);
151+
var context = new GitVersionContext(repo.Repository, new NullLog(), repo.Repository.Head, config);
151152
context.Configuration.Increment.ShouldBe(IncrementStrategy.Major);
152153
}
153154
}
154155
}
155-
}
156+
}

src/GitVersionCore.Tests/IntegrationTests/RemoteRepositoryScenarios.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Shouldly;
77
using GitVersion.Exceptions;
88
using GitVersion.Helpers;
9+
using GitVersion.Log;
910

1011
namespace GitVersionCore.Tests.IntegrationTests
1112
{
@@ -43,7 +44,7 @@ public void GivenARemoteGitRepositoryWithCommitsAndBranches_ThenClonedLocalShoul
4344
return repo;
4445
}))
4546
{
46-
GitRepositoryHelper.NormalizeGitDirectory(fixture.LocalRepositoryFixture.RepositoryPath, new AuthenticationInfo(), noFetch: false, currentBranch: string.Empty, true);
47+
GitRepositoryHelper.NormalizeGitDirectory(new NullLog(), fixture.LocalRepositoryFixture.RepositoryPath, new AuthenticationInfo(), noFetch: false, currentBranch: string.Empty, isDynamicRepository: true);
4748

4849
fixture.AssertFullSemver("1.0.0-beta.1+5");
4950
fixture.AssertFullSemver("1.0.0-beta.1+5", fixture.LocalRepositoryFixture.Repository);

src/GitVersionCore.Tests/TestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GitVersionCore.Tests
1+
namespace GitVersionCore.Tests
22
{
33
public class TestBase
44
{

src/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using GitTools.Testing;
44
using GitVersion;
55
using GitVersion.Configuration;
6+
using GitVersion.Log;
67
using GitVersion.VersionCalculation.BaseVersionCalculators;
78
using LibGit2Sharp;
89
using NUnit.Framework;
@@ -23,7 +24,7 @@ public void CanTakeVersionFromNameOfReleaseBranch(string branchName, string expe
2324
var branch = fixture.Repository.CreateBranch(branchName);
2425
var sut = new VersionInBranchNameBaseVersionStrategy();
2526

26-
var gitVersionContext = new GitVersionContext(fixture.Repository, branch, new Config().ApplyDefaults());
27+
var gitVersionContext = new GitVersionContext(fixture.Repository, new NullLog(), branch, new Config().ApplyDefaults());
2728
var baseVersion = sut.GetVersions(gitVersionContext).Single();
2829

2930
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
@@ -42,7 +43,7 @@ public void ShouldNotTakeVersionFromNameOfNonReleaseBranch(string branchName)
4243
var branch = fixture.Repository.CreateBranch(branchName);
4344
var sut = new VersionInBranchNameBaseVersionStrategy();
4445

45-
var gitVersionContext = new GitVersionContext(fixture.Repository, branch, new Config().ApplyDefaults());
46+
var gitVersionContext = new GitVersionContext(fixture.Repository, new NullLog(), branch, new Config().ApplyDefaults());
4647
var baseVersions = sut.GetVersions(gitVersionContext);
4748

4849
baseVersions.ShouldBeEmpty();
@@ -61,7 +62,7 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s
6162
var branchConfigs = new Dictionary<string, BranchConfig> { { "support", new BranchConfig { IsReleaseBranch = true } } };
6263
var config = new Config { Branches = branchConfigs }.ApplyDefaults();
6364

64-
var gitVersionContext = new GitVersionContext(fixture.Repository, branch, config);
65+
var gitVersionContext = new GitVersionContext(fixture.Repository, new NullLog(), branch, config);
6566
var baseVersion = sut.GetVersions(gitVersionContext).Single();
6667

6768
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
@@ -82,7 +83,7 @@ public void CanTakeVersionFromNameOfRemoteReleaseBranch(string branchName, strin
8283
fixture.LocalRepositoryFixture.Checkout($"origin/{branchName}");
8384

8485
var sut = new VersionInBranchNameBaseVersionStrategy();
85-
var gitVersionContext = new GitVersionContext(fixture.Repository, branch, new Config().ApplyDefaults());
86+
var gitVersionContext = new GitVersionContext(fixture.Repository, new NullLog(), branch, new Config().ApplyDefaults());
8687
var baseVersion = sut.GetVersions(gitVersionContext).Single();
8788

8889
baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);

src/GitVersionCore.Tests/VersionSourceTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using GitTools.Testing;
22
using GitVersion;
33
using GitVersion.Configuration;
4+
using GitVersion.Log;
45
using GitVersion.VersionCalculation;
56
using LibGit2Sharp;
67
using NUnit.Framework;
@@ -25,7 +26,7 @@ public void VersionSourceSha()
2526
Commands.Checkout(fixture.Repository, featureBranch);
2627
_ = fixture.Repository.MakeACommit();
2728

28-
var context = new GitVersionContext(fixture.Repository, fixture.Repository.Head, config);
29+
var context = new GitVersionContext(fixture.Repository, new NullLog(), fixture.Repository.Head, config);
2930
var nextVersionCalculator = new NextVersionCalculator();
3031
var version = nextVersionCalculator.FindVersion(context);
3132

@@ -43,7 +44,7 @@ public void VersionSourceShaOneCommit()
4344
{
4445
var initialCommit = fixture.Repository.MakeACommit();
4546

46-
var context = new GitVersionContext(fixture.Repository, fixture.Repository.Head, config);
47+
var context = new GitVersionContext(fixture.Repository, new NullLog(), fixture.Repository.Head, config);
4748
var nextVersionCalculator = new NextVersionCalculator();
4849
var version = nextVersionCalculator.FindVersion(context);
4950

@@ -67,7 +68,7 @@ public void VersionSourceShaUsingTag()
6768
Commands.Checkout(fixture.Repository, featureBranch);
6869
_ = fixture.Repository.MakeACommit();
6970

70-
var context = new GitVersionContext(fixture.Repository, fixture.Repository.Head, config);
71+
var context = new GitVersionContext(fixture.Repository, new NullLog(), fixture.Repository.Head, config);
7172
var nextVersionCalculator = new NextVersionCalculator();
7273
var version = nextVersionCalculator.FindVersion(context);
7374

src/GitVersionCore/Cache/GitVersionCacheKeyFactory.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
using System.Security.Cryptography;
66
using System.Text;
77
using GitVersion.Configuration;
8-
using GitVersion.Helpers;
98
using GitVersion.Common;
9+
using GitVersion.Log;
1010

1111
namespace GitVersion.Cache
1212
{
1313
class GitVersionCacheKeyFactory
1414
{
15-
public static GitVersionCacheKey Create(IFileSystem fileSystem, GitPreparer gitPreparer, Config overrideConfig, ConfigFileLocator configFileLocator)
15+
public static GitVersionCacheKey Create(IFileSystem fileSystem, ILog log, GitPreparer gitPreparer, Config overrideConfig, ConfigFileLocator configFileLocator)
1616
{
17-
var gitSystemHash = GetGitSystemHash(gitPreparer);
17+
var gitSystemHash = GetGitSystemHash(gitPreparer, log);
1818
var configFileHash = GetConfigFileHash(fileSystem, gitPreparer, configFileLocator);
1919
var repositorySnapshotHash = GetRepositorySnapshotHash(gitPreparer);
2020
var overrideConfigHash = GetOverrideConfigHash(overrideConfig);
@@ -23,18 +23,18 @@ public static GitVersionCacheKey Create(IFileSystem fileSystem, GitPreparer gitP
2323
return new GitVersionCacheKey(compositeHash);
2424
}
2525

26-
static string GetGitSystemHash(GitPreparer gitPreparer)
26+
static string GetGitSystemHash(GitPreparer gitPreparer, ILog log)
2727
{
2828
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
2929

3030
// traverse the directory and get a list of files, use that for GetHash
31-
var contents = CalculateDirectoryContents(Path.Combine(dotGitDirectory, "refs"));
31+
var contents = CalculateDirectoryContents(log, Path.Combine(dotGitDirectory, "refs"));
3232

3333
return GetHash(contents.ToArray());
3434
}
3535

3636
// based on https://msdn.microsoft.com/en-us/library/bb513869.aspx
37-
static List<string> CalculateDirectoryContents(string root)
37+
static List<string> CalculateDirectoryContents(ILog log, string root)
3838
{
3939
var result = new List<string>();
4040

@@ -72,12 +72,12 @@ static List<string> CalculateDirectoryContents(string root)
7272
// about the systems on which this code will run.
7373
catch (UnauthorizedAccessException e)
7474
{
75-
Logger.Error(e.Message);
75+
log.Error(e.Message);
7676
continue;
7777
}
7878
catch (DirectoryNotFoundException e)
7979
{
80-
Logger.Error(e.Message);
80+
log.Error(e.Message);
8181
continue;
8282
}
8383

@@ -88,12 +88,12 @@ static List<string> CalculateDirectoryContents(string root)
8888
}
8989
catch (UnauthorizedAccessException e)
9090
{
91-
Logger.Error(e.Message);
91+
log.Error(e.Message);
9292
continue;
9393
}
9494
catch (DirectoryNotFoundException e)
9595
{
96-
Logger.Error(e.Message);
96+
log.Error(e.Message);
9797
continue;
9898
}
9999

@@ -107,7 +107,7 @@ static List<string> CalculateDirectoryContents(string root)
107107
}
108108
catch (IOException e)
109109
{
110-
Logger.Error(e.Message);
110+
log.Error(e.Message);
111111
}
112112
}
113113

0 commit comments

Comments
 (0)