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
13 changes: 13 additions & 0 deletions src/GitVersionCore.Tests/ExecuteCoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ public void ConfigChangeInvalidatesCache()
});
}


[Test]
public void WorkingDirectoryWithoutGit()
{
var versionAndBranchFinder = new ExecuteCore(fileSystem);

RepositoryScope(versionAndBranchFinder, (fixture, vv) =>
{
var exception = Assert.Throws<DirectoryNotFoundException>(() => versionAndBranchFinder.ExecuteGitVersion(null, null, null, null, false, Environment.SystemDirectory, null));
exception.Message.ShouldContain("Can't find the .git directory in");
});
}

string RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
{
// Make sure GitVersion doesn't trigger build server mode when we are running the tests
Expand Down
7 changes: 6 additions & 1 deletion src/GitVersionCore/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ public string GetDotGitDirectory()
if (IsDynamicGitRepository)
return DynamicGitRepositoryPath;

var dotGitDirectory = Repository.Discover(targetPath).TrimEnd('/', '\\');
var dotGitDirectory = Repository.Discover(targetPath);

if (String.IsNullOrEmpty(dotGitDirectory))
throw new DirectoryNotFoundException("Can't find the .git directory in " + targetPath);

dotGitDirectory = dotGitDirectory.TrimEnd('/', '\\');
if (string.IsNullOrEmpty(dotGitDirectory))
throw new DirectoryNotFoundException("Can't find the .git directory in " + targetPath);

Expand Down
10 changes: 9 additions & 1 deletion src/GitVersionExe.Tests/ExecCmdLineArgumentTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using GitTools.Testing;
using NUnit.Framework;

Expand Down Expand Up @@ -65,4 +66,11 @@ public void InvalidWorkingDirectoryCrashesWithInformativeMessage()
var results = GitVersionHelper.ExecuteIn("InvalidDirectory", null, isTeamCity : false, logToFile : false);
results.Output.ShouldContain("InvalidDirectory");
}

[Test]
public void WorkingDirectoryWithoutGitFolderCrashesWithInformativeMessage()
{
var results = GitVersionHelper.ExecuteIn(Environment.SystemDirectory, null, isTeamCity: false, logToFile: false);
results.Output.ShouldContain("Can't find the .git directory in");
}
}