Skip to content

Issue #367 fix #503

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

Merged
merged 5 commits into from
Jul 15, 2015
Merged
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
5 changes: 5 additions & 0 deletions GitVersionCore/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void Initialise(bool normaliseGitDirectory)
}

var targetPath = CalculateTemporaryRepositoryPath(targetUrl, dynamicRepositoryLocation);

DynamicGitRepositoryPath = CreateDynamicRepository(targetPath, authentication, targetUrl, targetBranch, noFetch);
if (normaliseGitDirectory)
{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@
<Compile Include="LambdaEqualityHelper.cs" />
<Compile Include="LibGitExtensions.cs" />
<Compile Include="Logger.cs" />
<Compile Include="MissingBranchException.cs" />
<Compile Include="OutputFormatters\BuildOutputFormatter.cs" />
<Compile Include="OutputFormatters\JsonOutputFormatter.cs" />
<Compile Include="OutputType.cs" />
Expand Down
12 changes: 0 additions & 12 deletions GitVersionCore/MissingBranchException.cs

This file was deleted.

35 changes: 34 additions & 1 deletion GitVersionExe.Tests/GitPreparerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Exception>(() => gitPreparer.Initialise(true));
}
}
finally
{
Directory.Delete(tempDir, true);
}
}

// TODO test around normalisation
}
}