Skip to content

Improve shallow clone exception #1287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ namespace GitVersion
{
using System;

public class GitVersionConfigurationException : Exception
[Serializable]
public class GitVersionConfigurationException : GitVersionException
{
public GitVersionConfigurationException(string msg) : base(msg)
public GitVersionConfigurationException(string msg)
: base(msg)
{
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/GitVersionCore/Configuration/OldConfigurationException.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
namespace GitVersion
{
using System;
using System.Runtime.Serialization;

[Serializable]
public class OldConfigurationException : Exception
public class OldConfigurationException : GitVersionException
{
public OldConfigurationException(string message) : base(message)
{
}

protected OldConfigurationException(
SerializationInfo info,
StreamingContext context) : base(info, context)
public OldConfigurationException(string message)
: base(message)
{
}
}
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<Compile Include="GitVersionCache.cs" />
<Compile Include="GitVersionCacheKey.cs" />
<Compile Include="GitVersionCacheKeyFactory.cs" />
<Compile Include="GitVersionException.cs" />
<Compile Include="Helpers\EncodingHelper.cs" />
<Compile Include="Helpers\FileSystem.cs" />
<Compile Include="Helpers\IFileSystem.cs" />
Expand Down
21 changes: 21 additions & 0 deletions src/GitVersionCore/GitVersionException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace GitVersion
{
using System;

using GitTools;

[Serializable]
public class GitVersionException : GitToolsException
{
public GitVersionException(string message)
: base(message)
{
}


public GitVersionException(string message, Exception innerException)
: base(message, innerException)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,22 @@ public class FallbackBaseVersionStrategy : BaseVersionStrategy
{
public override IEnumerable<BaseVersion> GetVersions(GitVersionContext context)
{
var baseVersionSource = context.Repository.Commits.QueryBy(new CommitFilter
Commit baseVersionSource;
var currentBranchTip = context.CurrentBranch.Tip;

try
{
baseVersionSource = context.Repository.Commits.QueryBy(new CommitFilter
{
IncludeReachableFrom = currentBranchTip
}).First(c => !c.Parents.Any());
}
catch (NotFoundException exception)
{
IncludeReachableFrom = context.CurrentBranch.Tip
}).First(c => !c.Parents.Any());
yield return new BaseVersion(context, "Fallback base version", false, new SemanticVersion(minor: 1), baseVersionSource, null);
throw new GitVersionException($"Can't find commit {currentBranchTip.Sha}. Please ensure that the repository is an unshallow clone with `git fetch --unshallow`.", exception);
}

yield return new BaseVersion(context, "Fallback base version", false, new SemanticVersion(minor : 1), baseVersionSource, null);
}
}
}