diff --git a/GitVersionCore/GitPreparer.cs b/GitVersionCore/GitPreparer.cs
index 96ffb2309d..6a2ae11a25 100644
--- a/GitVersionCore/GitPreparer.cs
+++ b/GitVersionCore/GitPreparer.cs
@@ -43,6 +43,7 @@ public void Initialise(bool normaliseGitDirectory)
}
var targetPath = CalculateTemporaryRepositoryPath(targetUrl, dynamicRepositoryLocation);
+
DynamicGitRepositoryPath = CreateDynamicRepository(targetPath, authentication, targetUrl, targetBranch, noFetch);
if (normaliseGitDirectory)
{
@@ -119,6 +120,10 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti
Logger.WriteInfo(string.Format("Updating branch '{0}'", targetBranch));
using (var repo = new Repository(targetPath))
{
+ if (string.IsNullOrWhiteSpace(targetBranch))
+ {
+ throw new Exception("Dynamic Git repositories must have a target branch (/b)");
+ }
var targetGitBranch = repo.Branches[targetBranch];
var trackedBranch = targetGitBranch.TrackedBranch;
if (trackedBranch == null)
diff --git a/GitVersionCore/GitVersionCore.csproj b/GitVersionCore/GitVersionCore.csproj
index b33d56ef1e..a5db778b72 100644
--- a/GitVersionCore/GitVersionCore.csproj
+++ b/GitVersionCore/GitVersionCore.csproj
@@ -138,7 +138,6 @@
-
diff --git a/GitVersionCore/MissingBranchException.cs b/GitVersionCore/MissingBranchException.cs
deleted file mode 100644
index e280744a5c..0000000000
--- a/GitVersionCore/MissingBranchException.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-namespace GitVersion
-{
- using System;
- using LibGit2Sharp;
-
- public class MissingBranchException : Exception
- {
- public MissingBranchException(string message, LibGit2SharpException exception):base(message,exception)
- {
- }
- }
-}
\ No newline at end of file
diff --git a/GitVersionExe.Tests/GitPreparerTests.cs b/GitVersionExe.Tests/GitPreparerTests.cs
index 90a4eb9217..2dd6391c42 100644
--- a/GitVersionExe.Tests/GitPreparerTests.cs
+++ b/GitVersionExe.Tests/GitPreparerTests.cs
@@ -242,5 +242,38 @@ public void UsingDynamicRepositoryWithFeatureBranchWorks()
}
}
+ [Test]
+ public void UsingDynamicRepositoryWithoutTargetBranchFails()
+ {
+ var repoName = Guid.NewGuid().ToString();
+ var tempPath = Path.GetTempPath();
+ var tempDir = Path.Combine(tempPath, repoName);
+ Directory.CreateDirectory(tempDir);
+
+ try
+ {
+ using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
+ {
+ var commitId = mainRepositoryFixture.Repository.MakeACommit().Id.Sha;
+
+ var arguments = new Arguments
+ {
+ TargetPath = tempDir,
+ TargetUrl = mainRepositoryFixture.RepositoryPath,
+ CommitId = commitId
+ };
+
+ var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
+ gitPreparer.Initialise(true);
+
+ Assert.Throws(() => gitPreparer.Initialise(true));
+ }
+ }
+ finally
+ {
+ Directory.Delete(tempDir, true);
+ }
+ }
+
// TODO test around normalisation
-}
\ No newline at end of file
+}