Skip to content

Commit 29c16f6

Browse files
committed
fixes potential resource leaks
Fixes potential resource leaks by properly disposing of `Repository` instances.
1 parent 5acd9da commit 29c16f6

File tree

5 files changed

+10
-4
lines changed

5 files changed

+10
-4
lines changed

build/CI.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<File Path="../.github/workflows/homebrew.yml" />
4444
<File Path="../.github/workflows/mkdocs.yml" />
4545
<File Path="../.github/workflows/new-cli.yml" />
46+
<File Path="../.github/workflows/public-api.yml" />
4647
<File Path="../.github/workflows/release.yml" />
4748
<File Path="../.github/workflows/stale.yml" />
4849
<File Path="../.github/workflows/winget.yml" />

src/GitVersion.Core/Configuration/IgnoreConfigurationExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ public static IEnumerable<ICommit> Filter(this IIgnoreConfiguration ignore, ICom
2222
}
2323

2424
private static bool ShouldBeIgnored(ICommit commit, IIgnoreConfiguration ignore)
25-
=> !ignore.ToFilters().Any(filter => filter.Exclude(commit, out var _));
25+
=> !ignore.ToFilters().Any(filter => filter.Exclude(commit, out _));
2626
}

src/GitVersion.Core/VersionCalculation/ShaVersionFilter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ public bool Exclude(ICommit? commit, [NotNullWhen(true)] out string? reason)
3030

3131
if (commit == null
3232
|| !this.shaList.Any(sha => commit.Sha.StartsWith(sha, StringComparison.OrdinalIgnoreCase)))
33+
{
3334
return false;
35+
}
3436

3537
reason = $"Sha {commit} was ignored due to commit having been excluded by configuration";
3638
return true;

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public int UncommittedChangesCount()
6969

7070
public void Dispose()
7171
{
72-
if (this.repositoryLazy is { IsValueCreated: true }) RepositoryInstance.Dispose();
72+
if (this.repositoryLazy is not { IsValueCreated: true }) return;
73+
RepositoryInstance.Dispose();
74+
this.repositoryLazy = null;
7375
}
7476

7577
private int GetUncommittedChangesCountInternal()

src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ private string GetProjectRootDirectory()
8989
if (gitDirectory.IsNullOrEmpty())
9090
throw new DirectoryNotFoundException("Cannot find the .git directory");
9191

92-
return new Repository(gitDirectory).Info.WorkingDirectory;
92+
using var repo = new Repository(gitDirectory);
93+
return repo.Info.WorkingDirectory;
9394
}
9495

9596
private string? GetGitRootPath()
@@ -104,7 +105,7 @@ private static bool GitRepoHasMatchingRemote(string possiblePath, string targetU
104105
{
105106
try
106107
{
107-
var gitRepository = new Repository(possiblePath);
108+
using var gitRepository = new Repository(possiblePath);
108109
return gitRepository.Network.Remotes.Any(r => r.Url == targetUrl);
109110
}
110111
catch (Exception)

0 commit comments

Comments
 (0)