Skip to content

Commit 317aac8

Browse files
committed
Remove equality comparison from Remote
There are no semantics for determining whether a remote is like another one. The equality decision in libgit2sharp only looks at the name and urls, ignoring any other number of fields which affect how a remote behaves. For these reaons, rip it out. Equality (in as much as it's valuable) should be perform on whatever aspect the code is interested.
1 parent 5e683b9 commit 317aac8

File tree

3 files changed

+5
-49
lines changed

3 files changed

+5
-49
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public void CanResolveRemote()
394394
using (var repo = new Repository(path))
395395
{
396396
Branch master = repo.Branches["master"];
397-
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
397+
Assert.Equal("origin", master.Remote.Name);
398398
}
399399
}
400400

@@ -440,7 +440,7 @@ public void QueryRemoteForRemoteBranch()
440440
using (var repo = new Repository(path))
441441
{
442442
var master = repo.Branches["origin/master"];
443-
Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
443+
Assert.Equal("origin", master.Remote.Name);
444444
}
445445
}
446446

@@ -732,7 +732,7 @@ public void CanSetTrackedBranch()
732732

733733
Assert.True(branch.IsTracking);
734734
Assert.Equal(trackedBranch, branch.TrackedBranch);
735-
Assert.Equal(upstreamRemote, branch.Remote);
735+
Assert.Equal("origin", branch.Remote.Name);
736736
}
737737
}
738738

@@ -793,7 +793,7 @@ public void CanSetUpstreamBranch()
793793
Assert.True(updatedBranch.IsTracking);
794794
Assert.Equal(trackedBranch, updatedBranch.TrackedBranch);
795795
Assert.Equal(upstreamBranchName, updatedBranch.UpstreamBranchCanonicalName);
796-
Assert.Equal(upstreamRemote, updatedBranch.Remote);
796+
Assert.Equal(remoteName, updatedBranch.Remote.Name);
797797
}
798798
}
799799

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -123,28 +123,6 @@ public void CanSetRemotePushUrl()
123123
}
124124
}
125125

126-
[Fact]
127-
public void CanCheckEqualityOfRemote()
128-
{
129-
string path = SandboxStandardTestRepo();
130-
using (var repo = new Repository(path))
131-
{
132-
Remote oneOrigin = repo.Network.Remotes["origin"];
133-
Assert.NotNull(oneOrigin);
134-
135-
Remote otherOrigin = repo.Network.Remotes["origin"];
136-
Assert.Equal(oneOrigin, otherOrigin);
137-
138-
Remote createdRemote = repo.Network.Remotes.Add("origin2", oneOrigin.Url);
139-
140-
Remote loadedRemote = repo.Network.Remotes["origin2"];
141-
Assert.NotNull(loadedRemote);
142-
Assert.Equal(createdRemote, loadedRemote);
143-
144-
Assert.NotEqual(oneOrigin, loadedRemote);
145-
}
146-
}
147-
148126
[Fact]
149127
public void CreatingANewRemoteAddsADefaultRefSpec()
150128
{

LibGit2Sharp/Remote.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ namespace LibGit2Sharp
1212
/// A remote repository whose branches are tracked.
1313
/// </summary>
1414
[DebuggerDisplay("{DebuggerDisplay,nq}")]
15-
public class Remote : IEquatable<Remote>, IBelongToARepository, IDisposable
15+
public class Remote : IBelongToARepository, IDisposable
1616
{
17-
private static readonly LambdaEqualityHelper<Remote> equalityHelper =
18-
new LambdaEqualityHelper<Remote>(x => x.Name, x => x.Url, x => x.PushUrl);
19-
2017
internal readonly Repository repository;
2118

2219
private readonly RefSpecCollection refSpecs;
@@ -182,25 +179,6 @@ public override bool Equals(object obj)
182179
return Equals(obj as Remote);
183180
}
184181

185-
/// <summary>
186-
/// Determines whether the specified <see cref="Remote"/> is equal to the current <see cref="Remote"/>.
187-
/// </summary>
188-
/// <param name="other">The <see cref="Remote"/> to compare with the current <see cref="Remote"/>.</param>
189-
/// <returns>True if the specified <see cref="Remote"/> is equal to the current <see cref="Remote"/>; otherwise, false.</returns>
190-
public bool Equals(Remote other)
191-
{
192-
return equalityHelper.Equals(this, other);
193-
}
194-
195-
/// <summary>
196-
/// Returns the hash code for this instance.
197-
/// </summary>
198-
/// <returns>A 32-bit signed integer hash code.</returns>
199-
public override int GetHashCode()
200-
{
201-
return equalityHelper.GetHashCode(this);
202-
}
203-
204182
/// <summary>
205183
/// Tests if two <see cref="Remote"/> are equal.
206184
/// </summary>

0 commit comments

Comments
 (0)