Skip to content

Commit f480080

Browse files
committed
Simplify project files and replace redundant null argument checks
Replaces individual `<Compile>` entries in project files with a wildcard pattern for cleaner and more maintainable references. Removes redundant `nameof` argument from `ArgumentNullException.ThrowIfNull` calls. Adjusts solution structure to group projects logically and improves readability in unit tests.
1 parent 51a4fb0 commit f480080

File tree

7 files changed

+58
-107
lines changed

7 files changed

+58
-107
lines changed

new-cli/GitVersion.Core.Libgit2Sharp/GitVersion.Core.Libgit2Sharp.csproj

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,13 @@
55
</ItemGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\GitVersion.Common\GitVersion.Common.csproj" />
8+
<ProjectReference Include="..\GitVersion.Common\GitVersion.Common.csproj" />
99
</ItemGroup>
1010

1111
<ItemGroup>
12-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Branch.cs">
13-
<Link>Git\Branch.cs</Link>
14-
</Compile>
15-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\BranchCollection.cs">
16-
<Link>Git\BranchCollection.cs</Link>
17-
</Compile>
18-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Commit.cs">
19-
<Link>Git\Commit.cs</Link>
20-
</Compile>
21-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\CommitCollection.cs">
22-
<Link>Git\CommitCollection.cs</Link>
23-
</Compile>
24-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\GitObject.cs">
25-
<Link>Git\GitObject.cs</Link>
26-
</Compile>
27-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs">
28-
<Link>Git\GitRepository.cs</Link>
29-
</Compile>
30-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\ObjectId.cs">
31-
<Link>Git\ObjectId.cs</Link>
32-
</Compile>
33-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Reference.cs">
34-
<Link>Git\Reference.cs</Link>
35-
</Compile>
36-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\ReferenceCollection.cs">
37-
<Link>Git\ReferenceCollection.cs</Link>
38-
</Compile>
39-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RefSpec.cs">
40-
<Link>Git\RefSpec.cs</Link>
41-
</Compile>
42-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RefSpecCollection.cs">
43-
<Link>Git\RefSpecCollection.cs</Link>
44-
</Compile>
45-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Remote.cs">
46-
<Link>Git\Remote.cs</Link>
47-
</Compile>
48-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RemoteCollection.cs">
49-
<Link>Git\RemoteCollection.cs</Link>
50-
</Compile>
51-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\RepositoryExtensions.cs">
52-
<Link>Git\RepositoryExtensions.cs</Link>
53-
</Compile>
54-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\Tag.cs">
55-
<Link>Git\Tag.cs</Link>
56-
</Compile>
57-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TagCollection.cs">
58-
<Link>Git\TagCollection.cs</Link>
59-
</Compile>
60-
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\TreeChanges.cs">
61-
<Link>Git\TreeChanges.cs</Link>
62-
</Compile>
12+
<Compile Include="..\..\src\GitVersion.LibGit2Sharp\Git\*.cs" Link="Git\%(Filename)%(Extension)" />
13+
<Compile Remove="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepositoryInfo.cs" />
14+
<Compile Remove="..\..\src\GitVersion.LibGit2Sharp\Git\GitRepository.mutating.cs" />
6315
</ItemGroup>
6416

6517
</Project>

src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -146,27 +146,25 @@ private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pu
146146
using var fixture = new EmptyRepositoryFixture();
147147
var remoteRepositoryPath = FileSystemHelper.Path.GetRepositoryTempPath();
148148
RepositoryFixtureBase.Init(remoteRepositoryPath);
149-
using (var remoteRepository = new Repository(remoteRepositoryPath))
150-
{
151-
remoteRepository.Config.Set("user.name", "Test");
152-
remoteRepository.Config.Set("user.email", "[email protected]");
153-
fixture.Repository.Network.Remotes.Add("origin", remoteRepositoryPath);
154-
Console.WriteLine("Created git repository at {0}", remoteRepositoryPath);
155-
remoteRepository.MakeATaggedCommit("1.0.3");
156-
157-
var branch = remoteRepository.CreateBranch("FeatureBranch");
158-
Commands.Checkout(remoteRepository, branch);
159-
remoteRepository.MakeCommits(2);
160-
Commands.Checkout(remoteRepository, remoteRepository.Head.Tip.Sha);
161-
//Emulate merge commit
162-
var mergeCommitSha = remoteRepository.MakeACommit().Sha;
163-
Commands.Checkout(remoteRepository, TestBase.MainBranch); // HEAD cannot be pointing at the merge commit
164-
remoteRepository.Refs.Add(pullRequestRef, new ObjectId(mergeCommitSha));
165-
166-
// Checkout PR commit
167-
Commands.Fetch(fixture.Repository, "origin", [], new FetchOptions(), null);
168-
Commands.Checkout(fixture.Repository, mergeCommitSha);
169-
}
149+
using var remoteRepository = new Repository(remoteRepositoryPath);
150+
remoteRepository.Config.Set("user.name", "Test");
151+
remoteRepository.Config.Set("user.email", "[email protected]");
152+
fixture.Repository.Network.Remotes.Add("origin", remoteRepositoryPath);
153+
Console.WriteLine("Created git repository at {0}", remoteRepositoryPath);
154+
remoteRepository.MakeATaggedCommit("1.0.3");
155+
156+
var branch = remoteRepository.CreateBranch("FeatureBranch");
157+
Commands.Checkout(remoteRepository, branch);
158+
remoteRepository.MakeCommits(2);
159+
Commands.Checkout(remoteRepository, remoteRepository.Head.Tip.Sha);
160+
//Emulate merge commit
161+
var mergeCommitSha = remoteRepository.MakeACommit().Sha;
162+
Commands.Checkout(remoteRepository, TestBase.MainBranch); // HEAD cannot be pointing at the merge commit
163+
remoteRepository.Refs.Add(pullRequestRef, new ObjectId(mergeCommitSha));
164+
165+
// Checkout PR commit
166+
Commands.Fetch(fixture.Repository, "origin", [], new FetchOptions(), null);
167+
Commands.Checkout(fixture.Repository, mergeCommitSha);
170168

171169
var programFixture = new ProgramFixture(fixture.RepositoryPath);
172170
programFixture.WithOverrides(services =>
@@ -199,12 +197,12 @@ private static async Task VerifyPullRequestVersionIsCalculatedProperly(string pu
199197
public void VerifyPullRequestInput(string pullRequestRef, string friendly, bool isBranch, bool isPullRequest, bool isRemote)
200198
{
201199
var refName = new ReferenceName(pullRequestRef);
202-
Assert.Multiple(() =>
200+
using (Assert.EnterMultipleScope())
203201
{
204202
Assert.That(refName.Friendly, Is.EqualTo(friendly));
205203
Assert.That(refName.IsLocalBranch, Is.EqualTo(isBranch));
206204
Assert.That(refName.IsPullRequest, Is.EqualTo(isPullRequest));
207205
Assert.That(refName.IsRemoteBranch, Is.EqualTo(isRemote));
208-
});
206+
}
209207
}
210208
}

src/GitVersion.Core/Helpers/FileSystemHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ public static string GetTempPath()
8888

8989
public static string GetDirectoryName(string? path)
9090
{
91-
ArgumentNullException.ThrowIfNull(path, nameof(path));
91+
ArgumentNullException.ThrowIfNull(path);
9292

9393
return fileSystem.Path.GetDirectoryName(path)!;
9494
}
9595

9696
public static string GetFileName(string? path)
9797
{
98-
ArgumentNullException.ThrowIfNull(path, nameof(path));
98+
ArgumentNullException.ThrowIfNull(path);
9999

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

117117
public static string Combine(string? path1)
118118
{
119-
ArgumentNullException.ThrowIfNull(path1, nameof(path1));
119+
ArgumentNullException.ThrowIfNull(path1);
120120

121121
return fileSystem.Path.Combine(path1);
122122
}

src/GitVersion.LibGit2Sharp/Git/RefSpec.cs

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

44
namespace GitVersion.Git;
55

6-
internal class RefSpec : IRefSpec
6+
internal sealed class RefSpec : IRefSpec
77
{
88
private static readonly LambdaEqualityHelper<IRefSpec> equalityHelper = new(x => x.Specification);
99
private static readonly LambdaKeyComparer<IRefSpec, string> comparerHelper = new(x => x.Specification);

src/GitVersion.LibGit2Sharp/Git/Reference.cs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@
22
using GitVersion.Helpers;
33
using LibGit2Sharp;
44

5-
namespace GitVersion.Git
6-
{
7-
internal sealed class Reference : IReference
8-
{
9-
private static readonly LambdaEqualityHelper<IReference> equalityHelper = new(x => x.Name.Canonical);
10-
private static readonly LambdaKeyComparer<IReference, string> comparerHelper = new(x => x.Name.Canonical);
11-
internal readonly LibGit2Sharp.Reference innerReference;
5+
namespace GitVersion.Git;
126

13-
internal Reference(LibGit2Sharp.Reference reference)
14-
{
15-
this.innerReference = reference.NotNull();
16-
Name = new ReferenceName(reference.CanonicalName);
7+
internal sealed class Reference : IReference
8+
{
9+
private static readonly LambdaEqualityHelper<IReference> equalityHelper = new(x => x.Name.Canonical);
10+
private static readonly LambdaKeyComparer<IReference, string> comparerHelper = new(x => x.Name.Canonical);
11+
internal readonly LibGit2Sharp.Reference innerReference;
1712

18-
if (reference is DirectReference)
19-
ReferenceTargetId = new ObjectId(reference.TargetIdentifier);
20-
}
13+
internal Reference(LibGit2Sharp.Reference reference)
14+
{
15+
this.innerReference = reference.NotNull();
16+
Name = new ReferenceName(reference.CanonicalName);
2117

22-
public ReferenceName Name { get; }
23-
public IObjectId? ReferenceTargetId { get; }
24-
public int CompareTo(IReference? other) => comparerHelper.Compare(this, other);
25-
public override bool Equals(object? obj) => Equals(obj as IReference);
26-
public bool Equals(IReference? other) => equalityHelper.Equals(this, other);
27-
public override int GetHashCode() => equalityHelper.GetHashCode(this);
28-
public override string ToString() => Name.ToString();
29-
public string TargetIdentifier => this.innerReference.TargetIdentifier;
30-
public static implicit operator LibGit2Sharp.Reference(Reference d)
31-
=> d.NotNull().innerReference;
18+
if (reference is DirectReference)
19+
ReferenceTargetId = new ObjectId(reference.TargetIdentifier);
3220
}
21+
22+
public ReferenceName Name { get; }
23+
public IObjectId? ReferenceTargetId { get; }
24+
public int CompareTo(IReference? other) => comparerHelper.Compare(this, other);
25+
public override bool Equals(object? obj) => Equals(obj as IReference);
26+
public bool Equals(IReference? other) => equalityHelper.Equals(this, other);
27+
public override int GetHashCode() => equalityHelper.GetHashCode(this);
28+
public override string ToString() => Name.ToString();
29+
public string TargetIdentifier => this.innerReference.TargetIdentifier;
30+
public static implicit operator LibGit2Sharp.Reference(Reference d)
31+
=> d.innerReference;
3332
}

src/GitVersion.Output/TemplateManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class TemplateManager(TemplateType templateType)
1616

1717
public string? GetTemplateFor(string? fileExtension)
1818
{
19-
ArgumentNullException.ThrowIfNull(fileExtension, nameof(fileExtension));
19+
ArgumentNullException.ThrowIfNull(fileExtension);
2020

2121
string? result = null;
2222

@@ -30,7 +30,7 @@ internal class TemplateManager(TemplateType templateType)
3030

3131
public string? GetAddFormatFor(string? fileExtension)
3232
{
33-
ArgumentNullException.ThrowIfNull(fileExtension, nameof(fileExtension));
33+
ArgumentNullException.ThrowIfNull(fileExtension);
3434

3535
string? result = null;
3636

src/GitVersion.slnx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<Solution>
2+
<Folder Name="/misc/">
3+
<Project Path="GitVersion.Schema/GitVersion.Schema.csproj" />
4+
<Project Path="GitVersion.Testing/GitVersion.Testing.csproj" />
5+
</Folder>
26
<Folder Name="/modules/">
37
<Project Path="GitVersion.BuildAgents.Tests/GitVersion.BuildAgents.Tests.csproj" />
48
<Project Path="GitVersion.BuildAgents/GitVersion.BuildAgents.csproj" />
@@ -34,6 +38,4 @@
3438
<Project Path="GitVersion.Core/GitVersion.Core.csproj" />
3539
<Project Path="GitVersion.MsBuild.Tests/GitVersion.MsBuild.Tests.csproj" />
3640
<Project Path="GitVersion.MsBuild/GitVersion.MsBuild.csproj" />
37-
<Project Path="GitVersion.Schema/GitVersion.Schema.csproj" />
38-
<Project Path="GitVersion.Testing/GitVersion.Testing.csproj" />
3941
</Solution>

0 commit comments

Comments
 (0)