Skip to content

Commit 8921bf6

Browse files
gitfoolarturcic
authored andcommitted
Add tests for commit on current branch
1 parent 6c6695d commit 8921bf6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/GitVersionCore.Tests/Core/GitVersionExecutorTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,21 @@ public void WorkingDirectoryWithoutGit()
394394
exception.Message.ShouldContain("Can't find the .git directory in");
395395
}
396396

397+
[Test]
398+
public void WorkingDirectoryWithoutCommits()
399+
{
400+
using var fixture = new EmptyRepositoryFixture();
401+
402+
var gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath };
403+
404+
var exception = Assert.Throws<GitVersionException>(() =>
405+
{
406+
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
407+
gitVersionCalculator.CalculateVersionVariables();
408+
});
409+
exception.Message.ShouldContain("No commits found on the current branch.");
410+
}
411+
397412
[Test]
398413
[Category("NoMono")]
399414
[Description("LibGit2Sharp fails when running under Mono")]

src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@ public void WorkingDirectoryWithoutGitFolderFailsWithInformativeMessage()
8080
result.Output.ShouldContain("Can't find the .git directory in");
8181
}
8282

83+
[Test]
84+
public void WorkingDirectoryWithoutCommitsFailsWithInformativeMessage()
85+
{
86+
using var fixture = new EmptyRepositoryFixture();
87+
88+
var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null, logToFile: false);
89+
90+
result.ExitCode.ShouldNotBe(0);
91+
result.Output.ShouldContain("No commits found on the current branch.");
92+
}
93+
8394
[Test]
8495
public void WorkingDirectoryDoesNotExistFailsWithInformativeMessage()
8596
{

0 commit comments

Comments
 (0)