Skip to content

Commit 66bc2b0

Browse files
authored
Merge pull request #914 from asbjornu/feature/ResolveDynamicRepositoryIssue
Fixed issue with Dynamic Repostitories not working
2 parents 98f8b97 + a120a7b commit 66bc2b0

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/GitVersionCore.Tests/ExecuteCoreTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,17 @@ public void WorkingDirectoryWithoutGit()
127127
});
128128
}
129129

130+
[Test]
131+
public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
132+
{
133+
var versionAndBranchFinder = new ExecuteCore(fileSystem);
134+
135+
RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
136+
{
137+
versionAndBranchFinder.ExecuteGitVersion("https://github.com/GitTools/GitVersion.git", null, new Authentication(), "refs/head/master", false, fixture.RepositoryPath, null);
138+
});
139+
}
140+
130141
string RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
131142
{
132143
// Make sure GitVersion doesn't trigger build server mode when we are running the tests

src/GitVersionCore/ExecuteCore.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi
2727
var buildServer = applicableBuildServers.FirstOrDefault();
2828
var fetch = noFetch || (buildServer != null && buildServer.PreventFetch());
2929
var gitPreparer = new GitPreparer(targetUrl, dynamicRepositoryLocation, authentication, fetch, workingDirectory);
30+
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)));
3031
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
3132
var projectRoot = gitPreparer.GetProjectRootDirectory();
3233

@@ -42,7 +43,8 @@ public VersionVariables ExecuteGitVersion(string targetUrl, string dynamicReposi
4243
// },
4344
// Directory = workingDirectory
4445
//});
45-
Logger.WriteInfo(string.Format("Project root is: " + projectRoot));
46+
Logger.WriteInfo(string.Format("Project root is: {0}", projectRoot));
47+
Logger.WriteInfo(string.Format("DotGit directory is: {0}", dotGitDirectory));
4648
if (string.IsNullOrEmpty(dotGitDirectory) || string.IsNullOrEmpty(projectRoot))
4749
{
4850
// TODO Link to wiki article
@@ -92,8 +94,6 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch
9294

9395
VersionVariables ExecuteInternal(string targetBranch, string commitId, IRepository repo, GitPreparer gitPreparer, string projectRoot, IBuildServer buildServer, Config overrideConfig = null)
9496
{
95-
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, gitPreparer.IsDynamicGitRepository));
96-
9797
var versionFinder = new GitVersionFinder();
9898
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem, overrideConfig: overrideConfig);
9999

src/GitVersionCore/GitPreparer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,17 @@ public string GetDotGitDirectory()
111111

112112
public string GetProjectRootDirectory()
113113
{
114+
Logger.WriteInfo(string.Format("IsDynamicGitRepository: {0}", IsDynamicGitRepository));
114115
if (IsDynamicGitRepository)
116+
{
117+
Logger.WriteInfo(string.Format("Returning Project Root as {0}", targetPath));
115118
return targetPath;
119+
}
116120

117-
return Directory.GetParent(GetDotGitDirectory()).FullName;
121+
var dotGetGitDirectory = GetDotGitDirectory();
122+
var result = Directory.GetParent(dotGetGitDirectory).FullName;
123+
Logger.WriteInfo(string.Format("Returning Project Root from DotGitDirectory: {0} - {1}", dotGetGitDirectory, result));
124+
return result;
118125
}
119126

120127
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
165172
Checkout = false,
166173
CredentialsProvider = (url, usernameFromUrl, types) => credentials
167174
};
168-
Repository.Clone(repositoryUrl, gitDirectory, cloneOptions);
175+
var returnedPath = Repository.Clone(repositoryUrl, gitDirectory, cloneOptions);
176+
Logger.WriteInfo(string.Format("Returned path after repository clone: {0}", returnedPath));
169177
}
170178
catch (LibGit2SharpException ex)
171179
{

0 commit comments

Comments
 (0)