From d1b43fe0f0216c8162e0300644f9ecf9feadc780 Mon Sep 17 00:00:00 2001 From: Ruben Mamo Date: Tue, 24 May 2016 10:39:55 +0200 Subject: [PATCH 1/6] Fixed issue with Dynamic Repostitories not working --- src/GitVersionCore/ExecuteCore.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/GitVersionCore/ExecuteCore.cs b/src/GitVersionCore/ExecuteCore.cs index b0108faf6c..a0303378d5 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(false, targetBranch); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); From acce06c2786e3acc293b2a253b5475c62be5ddd0 Mon Sep 17 00:00:00 2001 From: Ruben Mamo Date: Thu, 26 May 2016 16:24:27 +0200 Subject: [PATCH 2/6] Added test for dynamic repositories Removed redundant call to gitPreparer.Initialise since it's now called earlier --- src/GitVersionCore.Tests/ExecuteCoreTests.cs | 11 +++++++++++ src/GitVersionCore/ExecuteCore.cs | 4 +--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/GitVersionCore.Tests/ExecuteCoreTests.cs b/src/GitVersionCore.Tests/ExecuteCoreTests.cs index e96c62d084..9db0626547 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, Environment.SystemDirectory, 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 a0303378d5..1371f7b82f 100644 --- a/src/GitVersionCore/ExecuteCore.cs +++ b/src/GitVersionCore/ExecuteCore.cs @@ -27,7 +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(false, targetBranch); + gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation))); var dotGitDirectory = gitPreparer.GetDotGitDirectory(); var projectRoot = gitPreparer.GetProjectRootDirectory(); @@ -93,8 +93,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); From a2b2bfe1c37b95c6e6b55a843f9c3516fbe95ed7 Mon Sep 17 00:00:00 2001 From: Ruben Mamo Date: Thu, 26 May 2016 16:53:45 +0200 Subject: [PATCH 3/6] Added additional logging to help with TravisCI debugging --- src/GitVersionCore/ExecuteCore.cs | 3 ++- src/GitVersionCore/GitPreparer.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/GitVersionCore/ExecuteCore.cs b/src/GitVersionCore/ExecuteCore.cs index 1371f7b82f..854b7babd6 100644 --- a/src/GitVersionCore/ExecuteCore.cs +++ b/src/GitVersionCore/ExecuteCore.cs @@ -43,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 diff --git a/src/GitVersionCore/GitPreparer.cs b/src/GitVersionCore/GitPreparer.cs index 5c9a7451f4..36e650b99f 100644 --- a/src/GitVersionCore/GitPreparer.cs +++ b/src/GitVersionCore/GitPreparer.cs @@ -165,7 +165,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) { From 35abeae5ef4e74b9b6720f30e389699e30d808c7 Mon Sep 17 00:00:00 2001 From: Ruben Mamo Date: Thu, 26 May 2016 18:08:27 +0200 Subject: [PATCH 4/6] Added even mor logging to identify why test is failing in TravisCI --- src/GitVersionCore/GitPreparer.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/GitVersionCore/GitPreparer.cs b/src/GitVersionCore/GitPreparer.cs index 36e650b99f..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) From d699cda31b9c499a1cfea64005565e2702b182fe Mon Sep 17 00:00:00 2001 From: Ruben Mamo Date: Thu, 26 May 2016 18:27:47 +0200 Subject: [PATCH 5/6] Dynamic Repository Test: Replaced local path from Environment.SystemDirectory to a fake name. --- src/GitVersionCore.Tests/ExecuteCoreTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/ExecuteCoreTests.cs b/src/GitVersionCore.Tests/ExecuteCoreTests.cs index 9db0626547..1643559596 100644 --- a/src/GitVersionCore.Tests/ExecuteCoreTests.cs +++ b/src/GitVersionCore.Tests/ExecuteCoreTests.cs @@ -134,7 +134,7 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory() RepositoryScope(versionAndBranchFinder, (fixture, vv) => { - versionAndBranchFinder.ExecuteGitVersion("https://github.com/GitTools/GitVersion.git", null, new Authentication(), "refs/head/master", false, Environment.SystemDirectory, null); + versionAndBranchFinder.ExecuteGitVersion("https://github.com/GitTools/GitVersion.git", null, new Authentication(), "refs/head/master", false, "tempProjectPath", null); }); } From a120a7bae706128e78f6beb22a67626ad6a1b823 Mon Sep 17 00:00:00 2001 From: Ruben Mamo Date: Fri, 27 May 2016 08:32:20 +0200 Subject: [PATCH 6/6] Changed path in Dynamic Repository Test --- src/GitVersionCore.Tests/ExecuteCoreTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/GitVersionCore.Tests/ExecuteCoreTests.cs b/src/GitVersionCore.Tests/ExecuteCoreTests.cs index 1643559596..ab4b43d98f 100644 --- a/src/GitVersionCore.Tests/ExecuteCoreTests.cs +++ b/src/GitVersionCore.Tests/ExecuteCoreTests.cs @@ -134,7 +134,7 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory() RepositoryScope(versionAndBranchFinder, (fixture, vv) => { - versionAndBranchFinder.ExecuteGitVersion("https://github.com/GitTools/GitVersion.git", null, new Authentication(), "refs/head/master", false, "tempProjectPath", null); + versionAndBranchFinder.ExecuteGitVersion("https://github.com/GitTools/GitVersion.git", null, new Authentication(), "refs/head/master", false, fixture.RepositoryPath, null); }); }