Skip to content

Commit fe1063f

Browse files
committed
Merge remote-tracking branch 'GeirGrusom/bugfix/issue-406'
2 parents 3049e66 + a0f8e39 commit fe1063f

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

GitVersionTask.Tests/GitVersionTask.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<Compile Include="Helpers\Lg2sHelperBase.cs" />
113113
<Compile Include="UpdateAssemblyInfoTests.cs" />
114114
<Compile Include="ModuleInitializer.cs" />
115+
<Compile Include="WriteVersionInfoToBuildLogTests.cs" />
115116
</ItemGroup>
116117
<ItemGroup>
117118
<None Include="app.config" />
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+

2+
namespace GitVersionTask.Tests
3+
{
4+
using System.IO;
5+
using NUnit.Framework;
6+
7+
[TestFixture]
8+
public class WriteVersionInfoToBuildLogTests
9+
{
10+
[Test]
11+
public void UsingInvalidGitDirectory_ThrowsDirectoryNotFoundException()
12+
{
13+
var task = new WriteVersionInfoToBuildLog
14+
{
15+
BuildEngine = new MockBuildEngine(),
16+
SolutionDirectory = Path.GetTempPath()
17+
};
18+
19+
Assert.That(task.InnerExecute, Throws.InstanceOf<DirectoryNotFoundException>());
20+
}
21+
}
22+
}

GitVersionTask/WriteVersionInfoToBuildLog.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
namespace GitVersionTask
22
{
3-
using System;
4-
using System.Collections.Generic;
53
using GitVersion;
64
using GitVersion.Helpers;
75
using Microsoft.Build.Framework;
86
using Microsoft.Build.Utilities;
7+
using System;
8+
using System.Collections.Generic;
9+
using System.IO;
910
using Logger = GitVersion.Logger;
1011

1112
public class WriteVersionInfoToBuildLog : Task
@@ -53,6 +54,10 @@ public void InnerExecute()
5354
{
5455
Tuple<CachedVersion, GitVersionContext> result;
5556
var gitDirectory = GitDirFinder.TreeWalkForDotGitDir(SolutionDirectory);
57+
58+
if (gitDirectory == null)
59+
throw new DirectoryNotFoundException(string.Format("Unable to locate a git repository in \"{0}\". Make sure that the solution is located in a git controlled folder. If you are using continous integration make sure that the sources are checked out on the build agent.", SolutionDirectory));
60+
5661
var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);
5762
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, configuration, NoFetch))
5863
{
@@ -68,8 +73,8 @@ public void InnerExecute()
6873
var versioningMode = config.VersioningMode;
6974

7075
var variablesFor = VariableProvider.GetVariablesFor(
71-
cachedVersion.SemanticVersion, assemblyVersioningScheme, versioningMode,
72-
config.ContinuousDeploymentFallbackTag,
76+
cachedVersion.SemanticVersion, assemblyVersioningScheme, versioningMode,
77+
config.ContinuousDeploymentFallbackTag,
7378
gitVersionContext.IsCurrentCommitTagged);
7479
WriteIntegrationParameters(cachedVersion, BuildServerList.GetApplicableBuildServers(authentication), variablesFor);
7580
}

0 commit comments

Comments
 (0)