Skip to content

Commit 9b336cd

Browse files
committed
Another small restructuring and removing busted test
1 parent 6d01254 commit 9b336cd

File tree

3 files changed

+20
-50
lines changed

3 files changed

+20
-50
lines changed

src/GitVersionCore/ExecuteCore.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ public ExecuteCore(IFileSystem fileSystem)
2121

2222
public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId)
2323
{
24-
var gitDir = Repository.Discover(workingDirectory);
25-
using (var repo = GetRepository(gitDir))
24+
// Normalise if we are running on build server
25+
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, noFetch, workingDirectory);
26+
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
27+
var projectRoot = gitPreparer.GetProjectRootDirectory();
28+
Logger.WriteInfo(string.Format("Project root is: " + projectRoot));
29+
if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
30+
{
31+
// TODO Link to wiki article
32+
throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory));
33+
}
34+
35+
using (var repo = GetRepository(dotGitDirectory))
2636
{
27-
var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(repo, gitDir);
37+
var versionVariables = gitVersionCache.LoadVersionVariablesFromDiskCache(repo, dotGitDirectory);
2838
if (versionVariables == null)
2939
{
30-
versionVariables = ExecuteInternal(targetUrl, dynamicRepositoryLocation, authentication, targetBranch, noFetch, workingDirectory, commitId, repo);
31-
gitVersionCache.WriteVariablesToDiskCache(repo, gitDir, versionVariables);
40+
versionVariables = ExecuteInternal(targetBranch, commitId, repo, gitPreparer, projectRoot);
41+
gitVersionCache.WriteVariablesToDiskCache(repo, dotGitDirectory, versionVariables);
3242
}
3343

3444
return versionVariables;
@@ -63,23 +73,13 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch
6373
return currentBranch;
6474
}
6575

66-
VersionVariables ExecuteInternal(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, string targetBranch, bool noFetch, string workingDirectory, string commitId, IRepository repo)
76+
VersionVariables ExecuteInternal(string targetBranch, string commitId, IRepository repo, GitPreparer gitPreparer, string projectRoot)
6777
{
68-
// Normalise if we are running on build server
69-
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, noFetch, workingDirectory);
7078
var applicableBuildServers = BuildServerList.GetApplicableBuildServers();
7179
var buildServer = applicableBuildServers.FirstOrDefault();
7280

7381
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch));
7482

75-
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
76-
var projectRoot = gitPreparer.GetProjectRootDirectory();
77-
Logger.WriteInfo(string.Format("Project root is: " + projectRoot));
78-
if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
79-
{
80-
// TODO Link to wiki article
81-
throw new Exception(string.Format("Failed to prepare or find the .git directory in path '{0}'.", workingDirectory));
82-
}
8383
var versionFinder = new GitVersionFinder();
8484
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem);
8585

src/GitVersionCore/GitPreparer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,17 @@ public string GetDotGitDirectory()
9393
return DynamicGitRepositoryPath;
9494
}
9595

96-
return Repository.Discover(this.targetPath);
96+
return Repository.Discover(targetPath);
9797
}
9898

9999
public string GetProjectRootDirectory()
100100
{
101101
if (IsDynamicGitRepository)
102-
return this.targetPath;
102+
return targetPath;
103103

104-
var gitDir = Repository.Discover(this.targetPath);
104+
var gitDir = Repository.Discover(targetPath);
105105

106-
if (String.IsNullOrEmpty(gitDir))
106+
if (string.IsNullOrEmpty(gitDir))
107107
throw new DirectoryNotFoundException("Can't find the .git directory in " + targetPath);
108108

109109
return Directory.GetParent(gitDir).FullName;

src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.IO;
22

33
using GitVersion;
4-
54
using NUnit.Framework;
65

76
using Shouldly;
@@ -61,35 +60,6 @@ public void InvalidArgumentsExitCodeShouldNotBeZero()
6160
}
6261
}
6362

64-
65-
[Test]
66-
public void UsesGitVersionConfigWhenCreatingDynamicRepository()
67-
{
68-
var localRepoPath = PathHelper.GetTempPath();
69-
var repoBasePath = Path.GetDirectoryName(PathHelper.GetTempPath());
70-
Directory.CreateDirectory(localRepoPath);
71-
72-
try
73-
{
74-
using (var remote = new EmptyRepositoryFixture(new Config()))
75-
{
76-
remote.Repository.MakeACommit();
77-
var configFile = Path.Combine(localRepoPath, "GitVersionConfig.yaml");
78-
File.WriteAllText(configFile, "next-version: 1.0.0");
79-
80-
var arguments = string.Format(" /url {0} /dynamicRepoLocation {1} /b master", remote.RepositoryPath, repoBasePath);
81-
var results = GitVersionHelper.ExecuteIn(localRepoPath, arguments, false);
82-
results.OutputVariables.SemVer.ShouldBe("1.0.0");
83-
}
84-
}
85-
finally
86-
{
87-
DeleteHelper.DeleteGitRepository(localRepoPath);
88-
DeleteHelper.DeleteGitRepository(repoBasePath);
89-
}
90-
}
91-
92-
9363
[Test]
9464
public void InvalidWorkingDirectoryCrashesWithInformativeMessage()
9565
{

0 commit comments

Comments
 (0)