Skip to content

Commit acce06c

Browse files
Ruben Mamoasbjornu
Ruben Mamo
authored andcommitted
Added test for dynamic repositories
Removed redundant call to gitPreparer.Initialise since it's now called earlier
1 parent d1b43fe commit acce06c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
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, Environment.SystemDirectory, 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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +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(false, targetBranch);
30+
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, !string.IsNullOrWhiteSpace(dynamicRepositoryLocation)));
3131
var dotGitDirectory = gitPreparer.GetDotGitDirectory();
3232
var projectRoot = gitPreparer.GetProjectRootDirectory();
3333

@@ -93,8 +93,6 @@ static string ResolveCurrentBranch(IBuildServer buildServer, string targetBranch
9393

9494
VersionVariables ExecuteInternal(string targetBranch, string commitId, IRepository repo, GitPreparer gitPreparer, string projectRoot, IBuildServer buildServer, Config overrideConfig = null)
9595
{
96-
gitPreparer.Initialise(buildServer != null, ResolveCurrentBranch(buildServer, targetBranch, gitPreparer.IsDynamicGitRepository));
97-
9896
var versionFinder = new GitVersionFinder();
9997
var configuration = ConfigurationProvider.Provide(projectRoot, fileSystem, overrideConfig: overrideConfig);
10098

0 commit comments

Comments
 (0)