Skip to content
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
17 changes: 16 additions & 1 deletion src/GitVersionCore.Tests/Core/GitVersionExecutorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,22 @@ public void WorkingDirectoryWithoutGit()
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
gitVersionCalculator.CalculateVersionVariables();
});
exception.Message.ShouldContain("Can't find the .git directory in");
exception.Message.ShouldContain("Cannot find the .git directory");
}

[Test]
public void WorkingDirectoryWithoutCommits()
{
using var fixture = new EmptyRepositoryFixture();

var gitVersionOptions = new GitVersionOptions { WorkingDirectory = fixture.RepositoryPath };

var exception = Assert.Throws<GitVersionException>(() =>
{
var gitVersionCalculator = GetGitVersionCalculator(gitVersionOptions);
gitVersionCalculator.CalculateVersionVariables();
});
exception.Message.ShouldContain("No commits found on the current branch.");
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersionCore/Extensions/GitVersionOptionsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static string GetDotGitDirectory(this GitVersionOptions gitVersionOptions

dotGitDirectory = dotGitDirectory?.TrimEnd('/', '\\');
if (string.IsNullOrEmpty(dotGitDirectory))
throw new DirectoryNotFoundException($"Can't find the .git directory in {dotGitDirectory}");
throw new DirectoryNotFoundException("Cannot find the .git directory");

return dotGitDirectory.Contains(Path.Combine(".git", "worktrees"))
? Directory.GetParent(Directory.GetParent(dotGitDirectory).FullName).FullName
Expand All @@ -32,7 +32,7 @@ public static string GetProjectRootDirectory(this GitVersionOptions gitVersionOp
var dotGitDirectory = Repository.Discover(gitVersionOptions.WorkingDirectory);

if (string.IsNullOrEmpty(dotGitDirectory))
throw new DirectoryNotFoundException($"Can't find the .git directory in {dotGitDirectory}");
throw new DirectoryNotFoundException("Cannot find the .git directory");

using var repository = new Repository(dotGitDirectory);
return repository.Info.WorkingDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ public override IEnumerable<BaseVersion> GetVersions()
{
Commit baseVersionSource;
var currentBranchTip = Context.CurrentBranch.Tip;
if (currentBranchTip == null)
{
throw new GitVersionException("No commits found on the current branch.");
}

try
{
baseVersionSource = repositoryMetadataProvider.GetBaseVersionSource(currentBranchTip);
}
catch (NotFoundException exception)
{
throw new GitVersionException($"Can't find commit {currentBranchTip.Sha}. Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception);
throw new GitVersionException($"Cannot find commit {currentBranchTip.Sha}. Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception);
}

yield return new BaseVersion("Fallback base version", false, new SemanticVersion(minor: 1), baseVersionSource, null);
Expand Down
13 changes: 12 additions & 1 deletion src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ public void WorkingDirectoryWithoutGitFolderFailsWithInformativeMessage()
var result = GitVersionHelper.ExecuteIn(Environment.SystemDirectory, arguments: null, logToFile: false);

result.ExitCode.ShouldNotBe(0);
result.Output.ShouldContain("Can't find the .git directory in");
result.Output.ShouldContain("Cannot find the .git directory");
}

[Test]
public void WorkingDirectoryWithoutCommitsFailsWithInformativeMessage()
{
using var fixture = new EmptyRepositoryFixture();

var result = GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: null, logToFile: false);

result.ExitCode.ShouldNotBe(0);
result.Output.ShouldContain("No commits found on the current branch.");
}

[Test]
Expand Down