Skip to content

Commit ab02c8c

Browse files
committed
Merge pull request #503 from RaphHaddad/issue-367
Issue #367 fix
2 parents 2379c9d + 88ede4a commit ab02c8c

File tree

4 files changed

+39
-14
lines changed

4 files changed

+39
-14
lines changed

GitVersionCore/GitPreparer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public void Initialise(bool normaliseGitDirectory)
4343
}
4444

4545
var targetPath = CalculateTemporaryRepositoryPath(targetUrl, dynamicRepositoryLocation);
46+
4647
DynamicGitRepositoryPath = CreateDynamicRepository(targetPath, authentication, targetUrl, targetBranch, noFetch);
4748
if (normaliseGitDirectory)
4849
{
@@ -119,6 +120,10 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti
119120
Logger.WriteInfo(string.Format("Updating branch '{0}'", targetBranch));
120121
using (var repo = new Repository(targetPath))
121122
{
123+
if (string.IsNullOrWhiteSpace(targetBranch))
124+
{
125+
throw new Exception("Dynamic Git repositories must have a target branch (/b)");
126+
}
122127
var targetGitBranch = repo.Branches[targetBranch];
123128
var trackedBranch = targetGitBranch.TrackedBranch;
124129
if (trackedBranch == null)

GitVersionCore/GitVersionCore.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@
138138
<Compile Include="LambdaEqualityHelper.cs" />
139139
<Compile Include="LibGitExtensions.cs" />
140140
<Compile Include="Logger.cs" />
141-
<Compile Include="MissingBranchException.cs" />
142141
<Compile Include="OutputFormatters\BuildOutputFormatter.cs" />
143142
<Compile Include="OutputFormatters\JsonOutputFormatter.cs" />
144143
<Compile Include="OutputType.cs" />

GitVersionCore/MissingBranchException.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

GitVersionExe.Tests/GitPreparerTests.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,38 @@ public void UsingDynamicRepositoryWithFeatureBranchWorks()
242242
}
243243
}
244244

245+
[Test]
246+
public void UsingDynamicRepositoryWithoutTargetBranchFails()
247+
{
248+
var repoName = Guid.NewGuid().ToString();
249+
var tempPath = Path.GetTempPath();
250+
var tempDir = Path.Combine(tempPath, repoName);
251+
Directory.CreateDirectory(tempDir);
252+
253+
try
254+
{
255+
using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config()))
256+
{
257+
var commitId = mainRepositoryFixture.Repository.MakeACommit().Id.Sha;
258+
259+
var arguments = new Arguments
260+
{
261+
TargetPath = tempDir,
262+
TargetUrl = mainRepositoryFixture.RepositoryPath,
263+
CommitId = commitId
264+
};
265+
266+
var gitPreparer = new GitPreparer(arguments.TargetUrl, arguments.DynamicRepositoryLocation, arguments.Authentication, arguments.TargetBranch, arguments.NoFetch, arguments.TargetPath);
267+
gitPreparer.Initialise(true);
268+
269+
Assert.Throws<Exception>(() => gitPreparer.Initialise(true));
270+
}
271+
}
272+
finally
273+
{
274+
Directory.Delete(tempDir, true);
275+
}
276+
}
277+
245278
// TODO test around normalisation
246-
}
279+
}

0 commit comments

Comments
 (0)