Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/GitVersionCore.Tests/ExecuteCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
{
// Make sure GitVersion doesn't trigger build server mode when we are running the tests
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersionCore/ExecuteCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 10 additions & 2 deletions src/GitVersionCore/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down