Skip to content

Commit 62438bc

Browse files
committed
Check that repository isn't a shallow clone and show an error if it is
1 parent 2c0c8df commit 62438bc

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

src/GitVersion.Core/Core/GitPreparer.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ private void NormalizeGitDirectory(bool noFetch, string? currentBranchName, bool
183183

184184
EnsureHeadIsAttachedToBranch(currentBranchName, authentication);
185185
EnsureRepositoryHeadDuringNormalisation(nameof(EnsureHeadIsAttachedToBranch), expectedSha);
186+
187+
if (this.repository.IsShallow)
188+
{
189+
throw new WarningException("Repository is a shallow clone. Git repositories must be contain the full history.");
190+
}
186191
}
187192

188193
private void EnsureRepositoryHeadDuringNormalisation(string occasion, string? expectedSha)

src/GitVersion.Core/Git/IGitRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public interface IGitRepository : IDisposable
55
string Path { get; }
66
string WorkingDirectory { get; }
77
bool IsHeadDetached { get; }
8+
bool IsShallow { get; }
89
IBranch Head { get; }
910
ITagCollection Tags { get; }
1011
IReferenceCollection Refs { get; }

src/GitVersion.Core/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ GitVersion.IGitRepository.FindMergeBase(GitVersion.ICommit! commit, GitVersion.I
335335
GitVersion.IGitRepository.GetNumberOfUncommittedChanges() -> int
336336
GitVersion.IGitRepository.Head.get -> GitVersion.IBranch!
337337
GitVersion.IGitRepository.IsHeadDetached.get -> bool
338+
GitVersion.IGitRepository.IsShallow.get -> bool
338339
GitVersion.IGitRepository.Path.get -> string!
339340
GitVersion.IGitRepository.Refs.get -> GitVersion.IReferenceCollection!
340341
GitVersion.IGitRepository.Remotes.get -> GitVersion.IRemoteCollection!

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private IRepository RepositoryInstance
2020
public string Path => RepositoryInstance.Info.Path;
2121
public string WorkingDirectory => RepositoryInstance.Info.WorkingDirectory;
2222
public bool IsHeadDetached => RepositoryInstance.Info.IsHeadDetached;
23+
public bool IsShallow => RepositoryInstance.Info.IsShallow;
2324
public IBranch Head => new Branch(RepositoryInstance.Head);
2425
public ITagCollection Tags => new TagCollection(RepositoryInstance.Tags);
2526
public IReferenceCollection Refs => new ReferenceCollection(RepositoryInstance.Refs);

0 commit comments

Comments
 (0)