Skip to content

Commit e979954

Browse files
committed
refactors: libgit2sharp extensions
Moves `ToGitRepository` extension method to `LibGit2SharpExtensions`. Makes `GitRepositoryInfo` class public.
1 parent 6f3f5fd commit e979954

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

src/GitVersion.Core.Tests/Extensions/GitRepositoryTestingExtensions.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using GitVersion.Extensions;
55
using GitVersion.Git;
66
using GitVersion.Helpers;
7-
using GitVersion.Logging;
87
using GitVersion.OutputVariables;
98
using GitVersion.VersionCalculation;
109
using LibGit2Sharp;
@@ -72,7 +71,7 @@ public static void DumpGraph(this IGitRepository repository, Action<string>? wri
7271
public static void DumpGraph(this IRepository repository, Action<string>? writer = null, int? maxCommits = null)
7372
=> DumpGraph(repository.ToGitRepository().Path, writer, maxCommits);
7473

75-
public static void RenameRemote(this LibGit2Sharp.RemoteCollection remotes, string oldName, string newName)
74+
public static void RenameRemote(this RemoteCollection remotes, string oldName, string newName)
7675
{
7776
if (oldName.IsEquivalentTo(newName)) return;
7877
if (remotes.Any(remote => remote.Name == newName))
@@ -180,13 +179,6 @@ public static void InitializeRepository(this RemoteRepositoryFixture fixture)
180179
gitPreparer.Prepare();
181180
}
182181

183-
internal static IGitRepository ToGitRepository(this IRepository repository)
184-
{
185-
var gitRepository = new GitRepository(new NullLog());
186-
gitRepository.DiscoverRepository(repository.Info.Path);
187-
return gitRepository;
188-
}
189-
190182
private static ServiceProvider ConfigureServices(Action<IServiceCollection>? servicesOverrides = null)
191183
{
192184
var services = new ServiceCollection()

src/GitVersion.LibGit2Sharp/Git/Commit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public IReadOnlyList<string> DiffPaths
3333
{
3434
if (!pathsCache.TryGetValue(this.Sha, out var paths))
3535
{
36-
paths = this.CommitChanges?.Paths ?? [];
36+
paths = this.CommitChanges.Paths;
3737
pathsCache[this.Sha] = paths;
3838
}
3939
return paths;

src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace GitVersion.Git;
88

9-
internal class GitRepositoryInfo : IGitRepositoryInfo
9+
public class GitRepositoryInfo : IGitRepositoryInfo
1010
{
1111
private readonly IFileSystem fileSystem;
1212
private readonly GitVersionOptions gitVersionOptions;

src/GitVersion.LibGit2Sharp/GitVersion.LibGit2Sharp.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,4 @@
88
<ProjectReference Include="..\GitVersion.Core\GitVersion.Core.csproj" />
99
</ItemGroup>
1010

11-
<ItemGroup>
12-
<InternalsVisibleTo Include="GitVersion.Core.Tests" />
13-
<InternalsVisibleTo Include="GitVersion.MsBuild.Tests" />
14-
</ItemGroup>
1511
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using GitVersion.Git;
2+
using GitVersion.Logging;
3+
using LibGit2Sharp;
4+
5+
namespace GitVersion;
6+
7+
public static class LibGit2SharpExtensions
8+
{
9+
public static IGitRepository ToGitRepository(this IRepository repository)
10+
{
11+
var gitRepository = new GitRepository(new NullLog());
12+
gitRepository.DiscoverRepository(repository.Info.Path);
13+
return gitRepository;
14+
}
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
11
#nullable enable
2+
GitVersion.Git.GitRepositoryInfo
3+
GitVersion.Git.GitRepositoryInfo.DotGitDirectory.get -> string?
4+
GitVersion.Git.GitRepositoryInfo.DynamicGitRepositoryPath.get -> string?
5+
GitVersion.Git.GitRepositoryInfo.GitRepositoryInfo(System.IO.Abstractions.IFileSystem! fileSystem, Microsoft.Extensions.Options.IOptions<GitVersion.GitVersionOptions!>! options) -> void
6+
GitVersion.Git.GitRepositoryInfo.GitRootPath.get -> string?
7+
GitVersion.Git.GitRepositoryInfo.ProjectRootDirectory.get -> string?
8+
GitVersion.LibGit2SharpExtensions
9+
static GitVersion.LibGit2SharpExtensions.ToGitRepository(this LibGit2Sharp.IRepository! repository) -> GitVersion.Git.IGitRepository!

src/GitVersion.slnx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<Solution>
2-
<Folder Name="/Modules/">
2+
<Folder Name="/modules/">
33
<Project Path="GitVersion.BuildAgents.Tests/GitVersion.BuildAgents.Tests.csproj" />
44
<Project Path="GitVersion.BuildAgents/GitVersion.BuildAgents.csproj" />
55
<Project Path="GitVersion.Configuration.Tests/GitVersion.Configuration.Tests.csproj" />
@@ -36,4 +36,4 @@
3636
<Project Path="GitVersion.MsBuild/GitVersion.MsBuild.csproj" />
3737
<Project Path="GitVersion.Schema/GitVersion.Schema.csproj" />
3838
<Project Path="GitVersion.Testing/GitVersion.Testing.csproj" />
39-
</Solution>
39+
</Solution>

0 commit comments

Comments
 (0)