Skip to content

Commit 35832d4

Browse files
author
Henning Moe
committed
Check for null when looking for a git directory and show an appropriate error. Fixes issue #406.
1 parent 2fca958 commit 35832d4

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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
@@ -51,6 +52,10 @@ public void InnerExecute()
5152
{
5253
Tuple<CachedVersion, GitVersionContext> result;
5354
var gitDirectory = GitDirFinder.TreeWalkForGitDir(SolutionDirectory);
55+
56+
if (gitDirectory == null)
57+
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));
58+
5459
var configuration = ConfigurationProvider.Provide(gitDirectory, fileSystem);
5560
if (!VersionAndBranchFinder.TryGetVersion(SolutionDirectory, out result, configuration))
5661
{
@@ -66,8 +71,8 @@ public void InnerExecute()
6671
var versioningMode = config.VersioningMode;
6772

6873
var variablesFor = VariableProvider.GetVariablesFor(
69-
cachedVersion.SemanticVersion, assemblyVersioningScheme, versioningMode,
70-
config.ContinuousDeploymentFallbackTag,
74+
cachedVersion.SemanticVersion, assemblyVersioningScheme, versioningMode,
75+
config.ContinuousDeploymentFallbackTag,
7176
gitVersionContext.IsCurrentCommitTagged);
7277
WriteIntegrationParameters(cachedVersion, BuildServerList.GetApplicableBuildServers(authentication), variablesFor);
7378
}

0 commit comments

Comments
 (0)