Skip to content

Fixed issue with Dynamic Repostitories not working #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 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, "tempProjectPath", null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the other tests in this file, fixture.RepositoryPath is what's used. Environment.SystemDirectory is used in the one test above just because it's guaranteed to:

  1. Exist.
  2. Not contain a .git folder.

});
}

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