Skip to content
Draft
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 @@ -5,61 +5,13 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GitVersion.Common\GitVersion.Common.csproj" />
<ProjectReference Include="..\GitVersion.Common\GitVersion.Common.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Branch.cs">
<Link>Git\Branch.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\BranchCollection.cs">
<Link>Git\BranchCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Commit.cs">
<Link>Git\Commit.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\CommitCollection.cs">
<Link>Git\CommitCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\GitObject.cs">
<Link>Git\GitObject.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs">
<Link>Git\GitRepository.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\ObjectId.cs">
<Link>Git\ObjectId.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Reference.cs">
<Link>Git\Reference.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\ReferenceCollection.cs">
<Link>Git\ReferenceCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RefSpec.cs">
<Link>Git\RefSpec.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RefSpecCollection.cs">
<Link>Git\RefSpecCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Remote.cs">
<Link>Git\Remote.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RemoteCollection.cs">
<Link>Git\RemoteCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RepositoryExtensions.cs">
<Link>Git\RepositoryExtensions.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Tag.cs">
<Link>Git\Tag.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TagCollection.cs">
<Link>Git\TagCollection.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TreeChanges.cs">
<Link>Git\TreeChanges.cs</Link>
</Compile>
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\*.cs" Link="Git\%(Filename)%(Extension)" />
<Compile Remove="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepositoryInfo.cs" />
<Compile Remove="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepository.mutating.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private static IRemote MockRemote(IGitRepository repository)
references["develop"].Returns(reference);
references.MockCollectionReturn(reference);

repository.Refs.Returns(references);
repository.References.Returns(references);
repository.Head.Returns(branch);
repository.Branches.Returns(branches);
return remote;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ private class MockCommit : ICommit
{
public bool Equals(ICommit? other) => throw new NotImplementedException();
public int CompareTo(ICommit? other) => throw new NotImplementedException();
public bool Equals(IGitObject? other) => throw new NotImplementedException();
public int CompareTo(IGitObject? other) => throw new NotImplementedException();
public IObjectId Id => throw new NotImplementedException();
public string Sha => throw new NotImplementedException();
public IReadOnlyList<ICommit> Parents => throw new NotImplementedException();
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersion.Core/Core/Abstractions/IRepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public interface IRepositoryStore

IReadOnlyList<ICommit> GetCommitLog(ICommit? baseVersionSource, ICommit currentCommit, IIgnoreConfiguration ignore);
IReadOnlyList<ICommit> GetCommitsReacheableFromHead(ICommit? headCommit, IIgnoreConfiguration ignore);
IReadOnlyList<ICommit> GetCommitsReacheableFrom(IGitObject commit, IBranch branch);
IReadOnlyList<ICommit> GetCommitsReacheableFrom(ICommit commit, IBranch branch);

IBranch GetTargetBranch(string? targetBranchName);
IBranch? FindBranch(ReferenceName branchName);
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.Core/Core/BranchesContainingCommitFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IEnumerable<IBranch> GetBranchesContainingCommit(ICommit commit, IEnumera
return InnerGetBranchesContainingCommit(commit, branches, onlyTrackedBranches);
}

private IEnumerable<IBranch> InnerGetBranchesContainingCommit(IGitObject commit, IEnumerable<IBranch> branches, bool onlyTrackedBranches)
private IEnumerable<IBranch> InnerGetBranchesContainingCommit(ICommit commit, IEnumerable<IBranch> branches, bool onlyTrackedBranches)
{
using (log.IndentLog($"Getting branches containing the commit '{commit.Id}'."))
{
Expand Down Expand Up @@ -63,6 +63,6 @@ private IEnumerable<IBranch> InnerGetBranchesContainingCommit(IGitObject commit,
private static bool IncludeTrackedBranches(IBranch branch, bool includeOnlyTracked)
=> (includeOnlyTracked && branch.IsTracking) || !includeOnlyTracked;

private static bool BranchTipIsNullOrCommit(IBranch branch, IGitObject commit)
private static bool BranchTipIsNullOrCommit(IBranch branch, ICommit commit)
=> branch.Tip == null || branch.Tip.Sha == commit.Sha;
}
18 changes: 9 additions & 9 deletions src/GitVersion.Core/Core/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ To disable this error set an environmental variable called IGNORE_NORMALISATION_

private void EnsureHeadIsAttachedToBranch(string? currentBranchName, AuthenticationInfo authentication)
{
var headSha = this.repository.Refs.Head?.TargetIdentifier;
var headSha = this.repository.References.Head?.TargetIdentifier;
if (!this.repository.IsHeadDetached)
{
this.log.Info($"HEAD points at branch '{headSha}'.");
return;
}

this.log.Info($"HEAD is detached and points at commit '{headSha}'.");
var localRefs = this.repository.Refs.FromGlob("*").Select(r => $"{r.Name.Canonical} ({r.TargetIdentifier})");
var localRefs = this.repository.References.FromGlob("*").Select(r => $"{r.Name.Canonical} ({r.TargetIdentifier})");
this.log.Info($"Local Refs:{FileSystemHelper.Path.NewLine}" + string.Join(FileSystemHelper.Path.NewLine, localRefs));

// In order to decide whether a fake branch is required or not, first check to see if any local branches have the same commit SHA of the head SHA.
Expand Down Expand Up @@ -331,7 +331,7 @@ private void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(string remoteName
var prefix = $"refs/remotes/{remoteName}/";
var remoteHeadCanonicalName = $"{prefix}HEAD";
var headReferenceName = ReferenceName.Parse(remoteHeadCanonicalName);
var remoteTrackingReferences = this.repository.Refs
var remoteTrackingReferences = this.repository.References
.FromGlob(prefix + "*")
.Where(r => !r.Name.Equals(headReferenceName));

Expand All @@ -344,7 +344,7 @@ private void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(string remoteName
// We do not want to touch our current branch
if (this.repository.Head.Name.EquivalentTo(branchName)) continue;

var localRef = this.repository.Refs[localReferenceName];
var localRef = this.repository.References[localReferenceName];
if (localRef != null)
{
if (localRef.TargetIdentifier == remoteTrackingReference.TargetIdentifier)
Expand All @@ -356,13 +356,13 @@ private void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(string remoteName
if (remoteRefTipId != null)
{
this.log.Info($"Updating local ref '{localRef.Name.Canonical}' to point at {remoteRefTipId}.");
this.retryAction.Execute(() => this.repository.Refs.UpdateTarget(localRef, remoteRefTipId));
this.retryAction.Execute(() => this.repository.References.UpdateTarget(localRef, remoteRefTipId));
}
continue;
}

this.log.Info($"Creating local branch from remote tracking '{remoteTrackingReference.Name.Canonical}'.");
this.repository.Refs.Add(localReferenceName.Canonical, remoteTrackingReference.TargetIdentifier, true);
this.repository.References.Add(localReferenceName.Canonical, remoteTrackingReference.TargetIdentifier, true);

var branch = this.repository.Branches[branchName];
if (branch != null)
Expand Down Expand Up @@ -406,17 +406,17 @@ public void EnsureLocalBranchExistsForCurrentBranch(IRemote remote, string? curr
this.log.Info(isLocalBranch
? $"Creating local branch {referenceName}"
: $"Creating local branch {referenceName} pointing at {repoTipId}");
this.repository.Refs.Add(localCanonicalName, repoTipId.Sha);
this.repository.References.Add(localCanonicalName, repoTipId.Sha);
}
else
{
this.log.Info(isLocalBranch
? $"Updating local branch {referenceName} to point at {repoTipId}"
: $"Updating local branch {referenceName} to match ref {currentBranch}");
var localRef = this.repository.Refs[localCanonicalName];
var localRef = this.repository.References[localCanonicalName];
if (localRef != null)
{
this.retryAction.Execute(() => this.repository.Refs.UpdateTarget(localRef, repoTipId));
this.retryAction.Execute(() => this.repository.References.UpdateTarget(localRef, repoTipId));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersion.Core/Core/RepositoryStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public IEnumerable<IBranch> GetSourceBranches(
{
var returnedBranches = new HashSet<IBranch>();

var referenceLookup = this.repository.Refs.ToLookup(r => r.TargetIdentifier);
var referenceLookup = this.repository.References.ToLookup(r => r.TargetIdentifier);

var commitBranches = FindCommitBranchesBranchedFrom(branch, configuration, excludedBranches).ToHashSet();

Expand Down Expand Up @@ -231,7 +231,7 @@ public IReadOnlyList<ICommit> GetCommitsReacheableFromHead(ICommit? headCommit,
return [.. ignore.Filter(commits)];
}

public IReadOnlyList<ICommit> GetCommitsReacheableFrom(IGitObject commit, IBranch branch)
public IReadOnlyList<ICommit> GetCommitsReacheableFrom(ICommit commit, IBranch branch)
{
var filter = new CommitFilter { IncludeReachableFrom = branch };

Expand Down
6 changes: 5 additions & 1 deletion src/GitVersion.Core/Git/ICommit.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace GitVersion.Git;

public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>, IGitObject
public interface ICommit : IEquatable<ICommit?>, IComparable<ICommit>
{
IReadOnlyList<ICommit> Parents { get; }

IObjectId Id { get; }

string Sha { get; }

DateTimeOffset When { get; }

string Message { get; }
Expand Down
7 changes: 0 additions & 7 deletions src/GitVersion.Core/Git/IGitObject.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/GitVersion.Core/Git/IGitRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IGitRepository : IDisposable
IBranch Head { get; }

ITagCollection Tags { get; }
IReferenceCollection Refs { get; }
IReferenceCollection References { get; }
IBranchCollection Branches { get; }
ICommitCollection Commits { get; }
IRemoteCollection Remotes { get; }
Expand Down
6 changes: 3 additions & 3 deletions src/GitVersion.Core/Helpers/FileSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ public static string GetTempPath()

public static string GetDirectoryName(string? path)
{
ArgumentNullException.ThrowIfNull(path, nameof(path));
ArgumentNullException.ThrowIfNull(path);

return fileSystem.Path.GetDirectoryName(path)!;
}

public static string GetFileName(string? path)
{
ArgumentNullException.ThrowIfNull(path, nameof(path));
ArgumentNullException.ThrowIfNull(path);

return fileSystem.Path.GetFileName(path);
}
Expand All @@ -116,7 +116,7 @@ public static string Combine(string? path1, string? path2)

public static string Combine(string? path1)
{
ArgumentNullException.ThrowIfNull(path1, nameof(path1));
ArgumentNullException.ThrowIfNull(path1);

return fileSystem.Path.Combine(path1);
}
Expand Down
5 changes: 0 additions & 5 deletions src/GitVersion.Core/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.Git.IBranch? branch,
GitVersion.Common.IRepositoryStore.FindMergeBase(GitVersion.Git.ICommit! commit, GitVersion.Git.ICommit! mainlineTip) -> GitVersion.Git.ICommit?
GitVersion.Common.IRepositoryStore.GetBranchesContainingCommit(GitVersion.Git.ICommit! commit, System.Collections.Generic.IEnumerable<GitVersion.Git.IBranch!>? branches = null, bool onlyTrackedBranches = false) -> System.Collections.Generic.IEnumerable<GitVersion.Git.IBranch!>!
GitVersion.Common.IRepositoryStore.GetCommitLog(GitVersion.Git.ICommit? baseVersionSource, GitVersion.Git.ICommit! currentCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.IGitObject! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFromHead(GitVersion.Git.ICommit? headCommit, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
GitVersion.Common.IRepositoryStore.GetCurrentCommit(GitVersion.Git.IBranch! currentBranch, string? commitId, GitVersion.Configuration.IIgnoreConfiguration! ignore) -> GitVersion.Git.ICommit?
GitVersion.Common.IRepositoryStore.GetForwardMerge(GitVersion.Git.ICommit? commitToFindCommonBase, GitVersion.Git.ICommit? findMergeBase) -> GitVersion.Git.ICommit?
Expand Down Expand Up @@ -227,9 +226,6 @@ GitVersion.Git.ICommit.When.get -> System.DateTimeOffset
GitVersion.Git.ICommitCollection
GitVersion.Git.ICommitCollection.GetCommitsPriorTo(System.DateTimeOffset olderThan) -> System.Collections.Generic.IEnumerable<GitVersion.Git.ICommit!>!
GitVersion.Git.ICommitCollection.QueryBy(GitVersion.Git.CommitFilter! commitFilter) -> System.Collections.Generic.IEnumerable<GitVersion.Git.ICommit!>!
GitVersion.Git.IGitObject
GitVersion.Git.IGitObject.Id.get -> GitVersion.Git.IObjectId!
GitVersion.Git.IGitObject.Sha.get -> string!
GitVersion.Git.IGitRepository
GitVersion.Git.IGitRepository.Branches.get -> GitVersion.Git.IBranchCollection!
GitVersion.Git.IGitRepository.Commits.get -> GitVersion.Git.ICommitCollection!
Expand All @@ -239,7 +235,6 @@ GitVersion.Git.IGitRepository.Head.get -> GitVersion.Git.IBranch!
GitVersion.Git.IGitRepository.IsHeadDetached.get -> bool
GitVersion.Git.IGitRepository.IsShallow.get -> bool
GitVersion.Git.IGitRepository.Path.get -> string!
GitVersion.Git.IGitRepository.Refs.get -> GitVersion.Git.IReferenceCollection!
GitVersion.Git.IGitRepository.Remotes.get -> GitVersion.Git.IRemoteCollection!
GitVersion.Git.IGitRepository.Tags.get -> GitVersion.Git.ITagCollection!
GitVersion.Git.IGitRepository.UncommittedChangesCount() -> int
Expand Down
4 changes: 4 additions & 0 deletions src/GitVersion.Core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
GitVersion.Common.IRepositoryStore.GetCommitsReacheableFrom(GitVersion.Git.ICommit! commit, GitVersion.Git.IBranch! branch) -> System.Collections.Generic.IReadOnlyList<GitVersion.Git.ICommit!>!
GitVersion.Git.ICommit.Id.get -> GitVersion.Git.IObjectId!
GitVersion.Git.ICommit.Sha.get -> string!
GitVersion.Git.IGitRepository.References.get -> GitVersion.Git.IReferenceCollection!
10 changes: 5 additions & 5 deletions src/GitVersion.LibGit2Sharp/Git/Branch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@

namespace GitVersion.Git;

internal sealed class Branch : IBranch
internal readonly struct Branch : IBranch
{
private static readonly LambdaEqualityHelper<IBranch> equalityHelper = new(x => x.Name.Canonical);
private static readonly LambdaKeyComparer<IBranch, string> comparerHelper = new(x => x.Name.Canonical);

private readonly LibGit2Sharp.Branch innerBranch;

internal Branch(LibGit2Sharp.Branch branch, LibGit2Sharp.Diff diff, GitRepository repo)
internal Branch(LibGit2Sharp.Branch branch, LibGit2Sharp.Diff diff, GitRepositoryCache repositoryCache)
{
diff.NotNull();
repo.NotNull();
repositoryCache.NotNull();
this.innerBranch = branch.NotNull();
Name = new(branch.CanonicalName);

var commit = this.innerBranch.Tip;
Tip = commit is null ? null : repo.GetOrCreate(commit, diff);
Tip = commit is null ? null : repositoryCache.GetOrWrap(commit, diff);

var commits = this.innerBranch.Commits;
Commits = new CommitCollection(commits, diff, repo);
Commits = new CommitCollection(commits, diff, repositoryCache);
}

public ReferenceName Name { get; }
Expand Down
13 changes: 6 additions & 7 deletions src/GitVersion.LibGit2Sharp/Git/BranchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ internal sealed class BranchCollection : IBranchCollection
private readonly LibGit2Sharp.BranchCollection innerCollection;
private readonly Lazy<IReadOnlyCollection<IBranch>> branches;
private readonly Diff diff;
private readonly GitRepository repo;
private readonly GitRepositoryCache repositoryCache;

internal BranchCollection(LibGit2Sharp.BranchCollection collection, Diff diff, GitRepository repo)
internal BranchCollection(LibGit2Sharp.BranchCollection collection, Diff diff, GitRepositoryCache repositoryCache)
{
this.innerCollection = collection.NotNull();
this.branches = new Lazy<IReadOnlyCollection<IBranch>>(() => [.. this.innerCollection.Select(branch => repo.GetOrCreate(branch, diff))]);
this.branches = new Lazy<IReadOnlyCollection<IBranch>>(() => [.. this.innerCollection.Select(branch => repositoryCache.GetOrWrap(branch, diff))]);
this.diff = diff.NotNull();
this.repo = repo.NotNull();
this.repositoryCache = repositoryCache.NotNull();
}

public IEnumerator<IBranch> GetEnumerator()
=> this.branches.Value.GetEnumerator();
public IEnumerator<IBranch> GetEnumerator() => this.branches.Value.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

Expand All @@ -29,7 +28,7 @@ public IBranch? this[string name]
{
name = name.NotNull();
var branch = this.innerCollection[name];
return branch is null ? null : this.repo.GetOrCreate(branch, this.diff);
return branch is null ? null : this.repositoryCache.GetOrWrap(branch, this.diff);
}
}

Expand Down
Loading
Loading