Skip to content

Commit 6bcfecf

Browse files
committed
Small code cleanup and fixed build server issues
1 parent c70c576 commit 6bcfecf

File tree

6 files changed

+17
-23
lines changed

6 files changed

+17
-23
lines changed

src/GitVersionCore.Tests/ExecuteCoreTests.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ExecuteCoreTests
1818
[SetUp]
1919
public void SetUp()
2020
{
21-
this.fileSystem = new FileSystem();
21+
fileSystem = new FileSystem();
2222
}
2323

2424

@@ -50,11 +50,11 @@ public void CacheFileExistsOnDisk()
5050
CommitDate: 2015-11-10
5151
";
5252

53-
var versionAndBranchFinder = new ExecuteCore(this.fileSystem);
53+
var versionAndBranchFinder = new ExecuteCore(fileSystem);
5454

5555
var info = RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
5656
{
57-
this.fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
57+
fileSystem.WriteAllText(vv.FileName, versionCacheFileContent);
5858
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null);
5959
vv.AssemblySemVer.ShouldBe("4.10.3.0");
6060
});
@@ -67,10 +67,11 @@ public void CacheFileExistsOnDisk()
6767
public void CacheFileExistsInMemory()
6868
{
6969
var cache = new ConcurrentDictionary<string, VersionVariables>();
70-
var versionAndBranchFinder = new ExecuteCore(this.fileSystem, cache.GetOrAdd);
70+
var versionAndBranchFinder = new ExecuteCore(fileSystem, cache.GetOrAdd);
7171

7272
var info = RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
7373
{
74+
vv.AssemblySemVer.ShouldBe("0.1.0.0");
7475
vv = versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, fixture.RepositoryPath, null);
7576
vv.AssemblySemVer.ShouldBe("0.1.0.0");
7677
});
@@ -90,9 +91,11 @@ public void CacheFileIsMissing()
9091

9192
string RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
9293
{
94+
// Make sure GitVersion doesn't trigger build server mode when we are running the tests
95+
Environment.SetEnvironmentVariable("APPVEYOR", null);
9396
var infoBuilder = new StringBuilder();
9497
Action<string> infoLogger = s => { infoBuilder.AppendLine(s); };
95-
executeCore = executeCore ?? new ExecuteCore(this.fileSystem);
98+
executeCore = executeCore ?? new ExecuteCore(fileSystem);
9699

97100
Logger.SetLoggers(infoLogger, s => { }, s => { });
98101

src/GitVersionCore.Tests/FileSystemTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using System;
22
using System.IO;
3-
using GitVersion;
4-
using GitVersion.Helpers;
5-
63
using LibGit2Sharp;
74
using NUnit.Framework;
85

src/GitVersionCore.Tests/Fixtures/RemoteRepositoryFixture.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using GitVersion;
3-
using GitVersion.Helpers;
4-
53
using LibGit2Sharp;
64

75
public class RemoteRepositoryFixture : RepositoryFixtureBase

src/GitVersionCore.Tests/GitPreparerTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System.IO;
33
using System.Linq;
44
using GitVersion;
5-
using GitVersion.Helpers;
6-
75
using LibGit2Sharp;
86
using NUnit.Framework;
97
using Shouldly;

src/GitVersionCore/ExecuteCore.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ public ExecuteCore(IFileSystem fileSystem, Func<string, Func<string, VersionVari
3434
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId)
3535
{
3636
var gitDir = Repository.Discover(workingDirectory);
37-
using (var repo = this.fileSystem.GetRepository(gitDir))
37+
using (var repo = fileSystem.GetRepository(gitDir))
3838
{
3939
// Maybe using timestamp in .git/refs directory is enough?
40-
var ticks = this.fileSystem.GetLastDirectoryWrite(Path.Combine(gitDir, "refs"));
40+
var ticks = fileSystem.GetLastDirectoryWrite(Path.Combine(gitDir, "refs"));
4141
var key = string.Format("{0}:{1}:{2}:{3}", gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks);
4242

43-
if (this.getOrAddFromCache != null)
43+
if (getOrAddFromCache != null)
4444
{
45-
return this.getOrAddFromCache(key, k =>
45+
return getOrAddFromCache(key, k =>
4646
{
4747
Logger.WriteInfo("Version not in memory cache. Attempting to load version from disk cache.");
4848
return LoadVersionVariablesFromDiskCache(key, gitDir, targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, workingDirectory, commitId);
@@ -97,11 +97,11 @@ VersionVariables LoadVersionVariablesFromDiskCache(string key, string gitDir, st
9797

9898
var cacheDir = Path.Combine(gitDir, "gitversion_cache");
9999
// If the cacheDir already exists, CreateDirectory just won't do anything (it won't fail). @asbjornu
100-
this.fileSystem.CreateDirectory(cacheDir);
100+
fileSystem.CreateDirectory(cacheDir);
101101

102102
var cacheFileName = string.Concat(Path.Combine(cacheDir, cacheKey), ".yml");
103103
VersionVariables vv = null;
104-
if (this.fileSystem.Exists(cacheFileName))
104+
if (fileSystem.Exists(cacheFileName))
105105
{
106106
using (Logger.IndentLog("Deserializing version variables from cache file " + cacheFileName))
107107
{
@@ -115,7 +115,7 @@ VersionVariables LoadVersionVariablesFromDiskCache(string key, string gitDir, st
115115
Logger.WriteInfo(ex.ToString());
116116
try
117117
{
118-
this.fileSystem.Delete(cacheFileName);
118+
fileSystem.Delete(cacheFileName);
119119
}
120120
catch (Exception deleteEx)
121121
{
@@ -179,7 +179,7 @@ VersionVariables ExecuteInternal(string targetUrl, string dynamicRepositoryLocat
179179
var versionFinder = new GitVersionFinder();
180180
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem);
181181

182-
using (var repo = this.fileSystem.GetRepository(dotGitDirectory))
182+
using (var repo = fileSystem.GetRepository(dotGitDirectory))
183183
{
184184
var gitVersionContext = new GitVersionContext(repo, configuration, commitId : commitId);
185185
var semanticVersion = versionFinder.FindVersion(gitVersionContext);

src/GitVersionExe.Tests/ExecutionResults.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
using System.Collections.Generic;
42
using System.Web.Script.Serialization;
53
using GitVersion;
64

0 commit comments

Comments
 (0)