Skip to content

Commit 489f9d0

Browse files
authored
Merge pull request #1287 from asbjornu/feature/improve-shallow-clone-exception
Improve shallow clone exception
2 parents 896ea71 + a90ce42 commit 489f9d0

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

src/GitVersionCore/Configuration/GitVersionConfigurationException.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ namespace GitVersion
22
{
33
using System;
44

5-
public class GitVersionConfigurationException : Exception
5+
[Serializable]
6+
public class GitVersionConfigurationException : GitVersionException
67
{
7-
public GitVersionConfigurationException(string msg) : base(msg)
8+
public GitVersionConfigurationException(string msg)
9+
: base(msg)
810
{
911
}
1012
}

src/GitVersionCore/Configuration/OldConfigurationException.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
namespace GitVersion
22
{
33
using System;
4-
using System.Runtime.Serialization;
54

65
[Serializable]
7-
public class OldConfigurationException : Exception
6+
public class OldConfigurationException : GitVersionException
87
{
9-
public OldConfigurationException(string message) : base(message)
10-
{
11-
}
12-
13-
protected OldConfigurationException(
14-
SerializationInfo info,
15-
StreamingContext context) : base(info, context)
8+
public OldConfigurationException(string message)
9+
: base(message)
1610
{
1711
}
1812
}

src/GitVersionCore/GitVersionCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
<Compile Include="GitVersionCache.cs" />
119119
<Compile Include="GitVersionCacheKey.cs" />
120120
<Compile Include="GitVersionCacheKeyFactory.cs" />
121+
<Compile Include="GitVersionException.cs" />
121122
<Compile Include="Helpers\EncodingHelper.cs" />
122123
<Compile Include="Helpers\FileSystem.cs" />
123124
<Compile Include="Helpers\IFileSystem.cs" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
5+
using GitTools;
6+
7+
[Serializable]
8+
public class GitVersionException : GitToolsException
9+
{
10+
public GitVersionException(string message)
11+
: base(message)
12+
{
13+
}
14+
15+
16+
public GitVersionException(string message, Exception innerException)
17+
: base(message, innerException)
18+
{
19+
}
20+
}
21+
}

src/GitVersionCore/VersionCalculation/FallbackBaseVersionStrategy.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@ public class FallbackBaseVersionStrategy : BaseVersionStrategy
1414
{
1515
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
1616
{
17-
var baseVersionSource = context.Repository.Commits.QueryBy(new CommitFilter
17+
Commit baseVersionSource;
18+
var currentBranchTip = context.CurrentBranch.Tip;
19+
20+
try
21+
{
22+
baseVersionSource = context.Repository.Commits.QueryBy(new CommitFilter
23+
{
24+
IncludeReachableFrom = currentBranchTip
25+
}).First(c => !c.Parents.Any());
26+
}
27+
catch (NotFoundException exception)
1828
{
19-
IncludeReachableFrom = context.CurrentBranch.Tip
20-
}).First(c => !c.Parents.Any());
21-
yield return new BaseVersion(context, "Fallback base version", false, new SemanticVersion(minor: 1), baseVersionSource, null);
29+
throw new GitVersionException($"Can't find commit {currentBranchTip.Sha}. Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception);
30+
}
31+
32+
yield return new BaseVersion(context, "Fallback base version", false, new SemanticVersion(minor : 1), baseVersionSource, null);
2233
}
2334
}
2435
}

0 commit comments

Comments
 (0)