diff --git a/src/GitVersionCore.Tests/ExecuteCoreTests.cs b/src/GitVersionCore.Tests/ExecuteCoreTests.cs index e96c62d084..ab4b43d98f 100644 --- a/src/GitVersionCore.Tests/ExecuteCoreTests.cs +++ b/src/GitVersionCore.Tests/ExecuteCoreTests.cs @@ -127,6 +127,17 @@ public void WorkingDirectoryWithoutGit() }); } + [Test] + public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory() + { + var versionAndBranchFinder = new ExecuteCore(fileSystem); + + RepositoryScope(versionAndBranchFinder, (fixture, vv) => + { + versionAndBranchFinder.ExecuteGitVersion("https://github.com/GitTools/GitVersion.git", null, new Authentication(), "refs/head/master", false, fixture.RepositoryPath, null); + }); + } + string RepositoryScope(ExecuteCore executeCore = null, Action fixtureAction = null) { // Make sure GitVersion doesn't trigger build server mode when we are running the tests diff --git a/src/GitVersionCore/ExecuteCore.cs b/src/GitVersionCore/ExecuteCore.cs index b0108faf6c..854b7babd6 100644 --- a/src/GitVersionCore/ExecuteCore.cs +++ b/src/GitVersionCore/ExecuteCore.cs @@ -27,6 +27,7 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi var buildServer = applicableBuildServers.FirstOrDefault(); var fetch = noFetch || (buildServer != null && buildServer.PreventFetch()); var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory); + gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation))); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); @@ -42,7 +43,8 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi // }, // Directory = workingDirectory //}); - Logger.WriteInfo(string.Format("Project root is: " + projectRoot)); + Logger.WriteInfo(string.Format("Project root is: {0}", projectRoot)); + Logger.WriteInfo(string.Format("DotGit directory is: {0}", dotGitDirectory)); if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot)) { // TODO Link to wiki article @@ -92,8 +94,6 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch VersionVariables ExecuteInternal(string targetBranch, string commitId, IRepository repo, GitPreparer gitPreparer, string projectRoot, IBuildServer buildServer, Config overrideConfig = null) { - gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, gitPreparer.IsDynamicGitRepository)); - var versionFinder = new GitVersionFinder(); var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem, overrideConfig: overrideConfig); diff --git a/src/GitVersionCore/GitPreparer.cs b/src/GitVersionCore/GitPreparer.cs index 5c9a7451f4..a26d228fab 100644 --- a/src/GitVersionCore/GitPreparer.cs +++ b/src/GitVersionCore/GitPreparer.cs @@ -111,10 +111,17 @@ public string GetDotGitDirectory() public string GetProjectRootDirectory() { + Logger.WriteInfo(string.Format("IsDynamicGitRepository: {0}", IsDynamicGitRepository)); if (IsDynamicGitRepository) + { + Logger.WriteInfo(string.Format("Returning Project Root as {0}", targetPath)); return targetPath; + } - return Directory.GetParent(GetDotGitDirectory()).FullName; + var dotGetGitDirectory = GetDotGitDirectory(); + var result = Directory.GetParent(dotGetGitDirectory).FullName; + Logger.WriteInfo(string.Format("Returning Project Root from DotGitDirectory: {0} - {1}", dotGetGitDirectory, result)); + return result; } static string CreateDynamicRepository(string targetPath, AuthenticationInfo authentication, string repositoryUrl, string targetBranch, bool noFetch) @@ -165,7 +172,8 @@ static void CloneRepository(string repositoryUrl, string gitDirectory, Authentic Checkout = false, CredentialsProvider = (url, usernameFromUrl, types) => credentials }; - Repository.Clone(repositoryUrl, gitDirectory, cloneOptions); + var returnedPath = Repository.Clone(repositoryUrl, gitDirectory, cloneOptions); + Logger.WriteInfo(string.Format("Returned path after repository clone: {0}", returnedPath)); } catch (LibGit2SharpException ex) {