Skip to content

Commit 84e9e65

Browse files
committed
reformating with resharper layout settings
1 parent 37592c4 commit 84e9e65

File tree

3 files changed

+116
-107
lines changed

3 files changed

+116
-107
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void CanCreateBranch()
2626
newBranch.Tip.Sha.ShouldEqual("be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
2727
repo.Branches.SingleOrDefault(p => p.Name == name).ShouldNotBeNull();
2828

29-
repo.Refs.Delete(newBranch.CanonicalName); //TODO: To be replaced with repo.Branches.Delete(newBranch.Name)
29+
repo.Refs.Delete(newBranch.CanonicalName); //TODO: To be replaced with repo.Branches.Delete(newBranch.Name)
3030
}
3131
}
3232

@@ -46,63 +46,39 @@ public void CanCreateBranchFromAnotherBranch()
4646
newBranch.Tip.Sha.ShouldEqual("4c062a6361ae6959e06292c1fa5e2822d9c96345");
4747
repo.Branches.SingleOrDefault(p => p.Name == name).ShouldNotBeNull();
4848

49-
repo.Refs.Delete(newBranch.CanonicalName); //TODO: To be replaced with repo.Branches.Delete(newBranch.Name)
49+
repo.Refs.Delete(newBranch.CanonicalName); //TODO: To be replaced with repo.Branches.Delete(newBranch.Name)
5050
}
5151
}
5252

5353
[Test]
54-
public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
55-
{
56-
using (var path = new TemporaryCloneOfTestRepo())
57-
using (var repo = new Repository(path.RepositoryPath))
58-
{
59-
var master = repo.Branches["refs/heads/master"];
60-
61-
var newBranch = repo.Branches.Create("clone-of-master", master.Tip.Sha);
62-
newBranch.IsCurrentRepositoryHead.ShouldBeFalse();
63-
}
64-
}
65-
66-
[Test]
67-
public void OnlyOneBranchIsTheHead()
54+
public void CanListAllBranches()
6855
{
6956
using (var repo = new Repository(Constants.TestRepoPath))
7057
{
71-
Branch head = null;
72-
73-
foreach (var branch in repo.Branches)
58+
foreach (var r in repo.Branches)
7459
{
75-
bool isHead = branch.IsCurrentRepositoryHead;
76-
77-
if (!isHead)
78-
{
79-
continue;
80-
}
81-
82-
if (head == null)
83-
{
84-
head = branch;
85-
continue;
86-
}
87-
88-
Assert.Fail("Both '{0}' and '{1}' appear to be Head.", head.CanonicalName, branch.CanonicalName);
60+
Assert.Contains(r.Name, expectedBranches);
8961
}
9062

91-
head.ShouldNotBeNull();
63+
repo.Branches.Count().ShouldEqual(5);
9264
}
9365
}
9466

9567
[Test]
96-
public void CanListAllBranches()
68+
public void CanLookupABranchByItsCanonicalName()
9769
{
9870
using (var repo = new Repository(Constants.TestRepoPath))
9971
{
100-
foreach (var r in repo.Branches)
101-
{
102-
Assert.Contains(r.Name, expectedBranches);
103-
}
72+
var branch = repo.Branches["refs/heads/br2"];
73+
branch.ShouldNotBeNull();
74+
branch.Name.ShouldEqual("br2");
10475

105-
repo.Branches.Count().ShouldEqual(5);
76+
var branch2 = repo.Branches["refs/heads/br2"];
77+
branch2.ShouldNotBeNull();
78+
branch2.Name.ShouldEqual("br2");
79+
80+
branch2.ShouldEqual(branch);
81+
(branch2 == branch).ShouldBeTrue();
10682
}
10783
}
10884

@@ -121,24 +97,6 @@ public void CanLookupLocalBranch()
12197
}
12298
}
12399

124-
[Test]
125-
public void CanLookupABranchByItsCanonicalName()
126-
{
127-
using (var repo = new Repository(Constants.TestRepoPath))
128-
{
129-
var branch = repo.Branches["refs/heads/br2"];
130-
branch.ShouldNotBeNull();
131-
branch.Name.ShouldEqual("br2");
132-
133-
var branch2 = repo.Branches["refs/heads/br2"];
134-
branch2.ShouldNotBeNull();
135-
branch2.Name.ShouldEqual("br2");
136-
137-
branch2.ShouldEqual(branch);
138-
(branch2 == branch).ShouldBeTrue();
139-
}
140-
}
141-
142100
[Test]
143101
public void CanWalkCommitsFromAnotherBranch()
144102
{
@@ -195,5 +153,47 @@ public void CreatingBranchWithNullTargetThrows()
195153
Assert.Throws<ArgumentNullException>(() => repo.Branches.Create("bad_branch", (ObjectId) null));
196154
}
197155
}
156+
157+
[Test]
158+
public void OnlyOneBranchIsTheHead()
159+
{
160+
using (var repo = new Repository(Constants.TestRepoPath))
161+
{
162+
Branch head = null;
163+
164+
foreach (var branch in repo.Branches)
165+
{
166+
bool isHead = branch.IsCurrentRepositoryHead;
167+
168+
if (!isHead)
169+
{
170+
continue;
171+
}
172+
173+
if (head == null)
174+
{
175+
head = branch;
176+
continue;
177+
}
178+
179+
Assert.Fail("Both '{0}' and '{1}' appear to be Head.", head.CanonicalName, branch.CanonicalName);
180+
}
181+
182+
head.ShouldNotBeNull();
183+
}
184+
}
185+
186+
[Test]
187+
public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
188+
{
189+
using (var path = new TemporaryCloneOfTestRepo())
190+
using (var repo = new Repository(path.RepositoryPath))
191+
{
192+
var master = repo.Branches["refs/heads/master"];
193+
194+
var newBranch = repo.Branches.Create("clone-of-master", master.Tip.Sha);
195+
newBranch.IsCurrentRepositoryHead.ShouldBeFalse();
196+
}
197+
}
198198
}
199199
}

LibGit2Sharp/Branch.cs

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ namespace LibGit2Sharp
88
/// </summary>
99
public class Branch : IEquatable<Branch>
1010
{
11-
private readonly Repository repo;
12-
1311
private static readonly LambdaEqualityHelper<Branch> equalityHelper =
14-
new LambdaEqualityHelper<Branch>(new Func<Branch, object>[] { x => x.CanonicalName, x => x.Tip });
12+
new LambdaEqualityHelper<Branch>(new Func<Branch, object>[] {x => x.CanonicalName, x => x.Tip});
13+
14+
private readonly Repository repo;
1515

1616
/// <summary>
1717
/// Initializes a new instance of the <see cref = "Branch" /> class.
1818
/// </summary>
19-
/// <param name="tip">The commit which is pointed at by this Branch</param>
19+
/// <param name = "tip">The commit which is pointed at by this Branch</param>
2020
/// <param name = "repo">The repo.</param>
21-
/// <param name="canonicalName">The full name of the reference</param>
21+
/// <param name = "canonicalName">The full name of the reference</param>
2222
internal Branch(string canonicalName, Commit tip, Repository repo)
2323
{
2424
this.repo = repo;
@@ -34,21 +34,27 @@ internal Branch(string canonicalName, Commit tip, Repository repo)
3434
/// <summary>
3535
/// Gets the name of this branch.
3636
/// </summary>
37-
public string Name { get { return ShortenName(CanonicalName); } }
37+
public string Name
38+
{
39+
get { return ShortenName(CanonicalName); }
40+
}
3841

3942
/// <summary>
40-
/// Gets a value indicating whether this instance is a remote.
43+
/// Gets a value indicating whether this instance is a remote.
4144
/// </summary>
4245
/// <value>
4346
/// <c>true</c> if this instance is remote; otherwise, <c>false</c>.
4447
/// </value>
45-
public bool IsRemote { get { return IsRemoteBranch(CanonicalName); } }
48+
public bool IsRemote
49+
{
50+
get { return IsRemoteBranch(CanonicalName); }
51+
}
4652

4753
/// <summary>
48-
/// Gets a value indicating whether this instance is current branch (HEAD) in the repository.
54+
/// Gets a value indicating whether this instance is current branch (HEAD) in the repository.
4955
/// </summary>
5056
/// <value>
51-
/// <c>true</c> if this instance is current branch; otherwise, <c>false</c>.
57+
/// <c>true</c> if this instance is current branch; otherwise, <c>false</c>.
5258
/// </value>
5359
public bool IsCurrentRepositoryHead
5460
{
@@ -68,6 +74,39 @@ public CommitCollection Commits
6874
get { return repo.Commits.StartingAt(this); }
6975
}
7076

77+
#region IEquatable<Branch> Members
78+
79+
/// <summary>
80+
/// Determines whether the specified <see cref = "Branch" /> is equal to the current <see cref = "Branch" />.
81+
/// </summary>
82+
/// <param name = "other">The <see cref = "Branch" /> to compare with the current <see cref = "Branch" />.</param>
83+
/// <returns>True if the specified <see cref = "Branch" /> is equal to the current <see cref = "Branch" />; otherwise, false.</returns>
84+
public bool Equals(Branch other)
85+
{
86+
return equalityHelper.Equals(this, other);
87+
}
88+
89+
#endregion
90+
91+
/// <summary>
92+
/// Determines whether the specified <see cref = "Object" /> is equal to the current <see cref = "Branch" />.
93+
/// </summary>
94+
/// <param name = "obj">The <see cref = "Object" /> to compare with the current <see cref = "Branch" />.</param>
95+
/// <returns>True if the specified <see cref = "Object" /> is equal to the current <see cref = "Branch" />; otherwise, false.</returns>
96+
public override bool Equals(object obj)
97+
{
98+
return Equals(obj as Branch);
99+
}
100+
101+
/// <summary>
102+
/// Returns the hash code for this instance.
103+
/// </summary>
104+
/// <returns>A 32-bit signed integer hash code.</returns>
105+
public override int GetHashCode()
106+
{
107+
return equalityHelper.GetHashCode(this);
108+
}
109+
71110
private static bool IsRemoteBranch(string canonicalName)
72111
{
73112
return canonicalName.StartsWith("refs/remotes/");
@@ -89,50 +128,21 @@ private static string ShortenName(string branchName)
89128
}
90129

91130
/// <summary>
92-
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Branch"/>.
93-
/// </summary>
94-
/// <param name="obj">The <see cref="Object"/> to compare with the current <see cref="Branch"/>.</param>
95-
/// <returns>True if the specified <see cref="Object"/> is equal to the current <see cref="Branch"/>; otherwise, false.</returns>
96-
public override bool Equals(object obj)
97-
{
98-
return Equals(obj as Branch);
99-
}
100-
101-
/// <summary>
102-
/// Determines whether the specified <see cref="Branch"/> is equal to the current <see cref="Branch"/>.
103-
/// </summary>
104-
/// <param name="other">The <see cref="Branch"/> to compare with the current <see cref="Branch"/>.</param>
105-
/// <returns>True if the specified <see cref="Branch"/> is equal to the current <see cref="Branch"/>; otherwise, false.</returns>
106-
public bool Equals(Branch other)
107-
{
108-
return equalityHelper.Equals(this, other);
109-
}
110-
111-
/// <summary>
112-
/// Returns the hash code for this instance.
113-
/// </summary>
114-
/// <returns>A 32-bit signed integer hash code.</returns>
115-
public override int GetHashCode()
116-
{
117-
return equalityHelper.GetHashCode(this);
118-
}
119-
120-
/// <summary>
121-
/// Tests if two <see cref="Branch"/> are equal.
131+
/// Tests if two <see cref = "Branch" /> are equal.
122132
/// </summary>
123-
/// <param name="left">First <see cref="Branch"/> to compare.</param>
124-
/// <param name="right">Second <see cref="Branch"/> to compare.</param>
133+
/// <param name = "left">First <see cref = "Branch" /> to compare.</param>
134+
/// <param name = "right">Second <see cref = "Branch" /> to compare.</param>
125135
/// <returns>True if the two objects are equal; false otherwise.</returns>
126136
public static bool operator ==(Branch left, Branch right)
127137
{
128138
return Equals(left, right);
129139
}
130140

131141
/// <summary>
132-
/// Tests if two <see cref="Branch"/> are different.
142+
/// Tests if two <see cref = "Branch" /> are different.
133143
/// </summary>
134-
/// <param name="left">First <see cref="Branch"/> to compare.</param>
135-
/// <param name="right">Second <see cref="Branch"/> to compare.</param>
144+
/// <param name = "left">First <see cref = "Branch" /> to compare.</param>
145+
/// <param name = "right">Second <see cref = "Branch" /> to compare.</param>
136146
/// <returns>True if the two objects are different; false otherwise.</returns>
137147
public static bool operator !=(Branch left, Branch right)
138148
{

LibGit2Sharp/BranchCollection.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Globalization;
54
using System.Linq;
65
using LibGit2Sharp.Core;
76

@@ -57,13 +56,13 @@ IEnumerator IEnumerable.GetEnumerator()
5756
public Branch Create(string name, string target)
5857
{
5958
ObjectId id = ObjectId.CreateFromMaybeSha(target);
60-
if(id != null)
59+
if (id != null)
6160
{
6261
return Create(name, id);
6362
}
6463

6564
repo.Refs.Create(NormalizeToCanonicalName(name), NormalizeToCanonicalName(target));
66-
65+
6766
return this[name];
6867
}
6968

@@ -78,7 +77,7 @@ public Branch Create(string name, ObjectId target)
7877
Ensure.ArgumentNotNull(target, "target");
7978

8079
repo.Refs.Create(NormalizeToCanonicalName(name), target);
81-
80+
8281
return this[name];
8382
}
8483

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy