Skip to content

Commit 91148d8

Browse files
committed
added IRemoteCollection
1 parent 001deaf commit 91148d8

File tree

6 files changed

+44
-10
lines changed

6 files changed

+44
-10
lines changed

src/GitVersion.LibGit2Sharp/Git/GitRepository.cs

+3-6
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,7 @@ public void Dispose()
6969
public string Path => repositoryInstance.Info.Path;
7070
public string WorkingDirectory => repositoryInstance.Info.WorkingDirectory;
7171
public bool IsHeadDetached => repositoryInstance.Info.IsHeadDetached;
72-
public IGitRepository CreateNew(string gitRootPath)
73-
{
74-
return new GitRepository(new NullLog(), () => gitRootPath);
75-
}
72+
public IGitRepository CreateNew(string gitRootPath) => new GitRepository(new NullLog(), () => gitRootPath);
7673
public int GetNumberOfUncommittedChanges()
7774
{
7875
// check if we have a branch tip at all to behave properly with empty repos
@@ -116,9 +113,9 @@ public string ShortenObjectId(ICommit commit)
116113

117114
public ITagCollection Tags => new TagCollection(repositoryInstance.Tags);
118115
public IReferenceCollection Refs => new ReferenceCollection(repositoryInstance.Refs);
119-
120116
public IBranchCollection Branches => new BranchCollection(repositoryInstance.Branches);
121117
public ICommitCollection Commits => new CommitCollection(repositoryInstance.Commits);
118+
public IRemoteCollection Remotes => new RemoteCollection(repositoryInstance.Network.Remotes);
122119

123120
public void CreateBranchForPullRequestBranch(AuthenticationInfo auth)
124121
{
@@ -176,7 +173,7 @@ public void CreateBranchForPullRequestBranch(AuthenticationInfo auth)
176173
log.Info($"Checking local branch '{fakeBranchName}' out.");
177174
Checkout(fakeBranchName);
178175
}
179-
public bool GitRepoHasMatchingRemote(string targetUrl)
176+
public bool AnyMatchingRemote(string targetUrl)
180177
{
181178
return repositoryInstance.Network.Remotes.Any(r => r.Url == targetUrl);
182179
}

src/GitVersion.LibGit2Sharp/Git/GitRepositoryInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private static bool GitRepoHasMatchingRemote(string possiblePath, string targetU
102102
{
103103
try
104104
{
105-
return new GitRepository(new NullLog(), possiblePath).GitRepoHasMatchingRemote(targetUrl);
105+
return new GitRepository(new NullLog(), possiblePath).AnyMatchingRemote(targetUrl);
106106
}
107107
catch (Exception)
108108
{

src/GitVersion.LibGit2Sharp/Git/ReferenceCollection.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ public void UpdateTarget(IReference directRef, IObjectId targetId)
2525
}
2626

2727
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
28+
2829
public IReference? this[string name]
2930
{
3031
get
3132
{
32-
var branch = innerCollection[name];
33-
return branch is null ? null : new Reference(branch);
33+
var reference = innerCollection[name];
34+
return reference is null ? null : new Reference(reference);
3435
}
3536
}
3637

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
5+
namespace GitVersion
6+
{
7+
internal sealed class RemoteCollection : IRemoteCollection
8+
{
9+
private readonly LibGit2Sharp.RemoteCollection innerCollection;
10+
internal RemoteCollection(LibGit2Sharp.RemoteCollection collection) => innerCollection = collection;
11+
12+
public IEnumerator<IRemote> GetEnumerator()
13+
{
14+
return innerCollection.Select(reference => new Remote(reference)).GetEnumerator();
15+
}
16+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
17+
18+
public IRemote? this[string name]
19+
{
20+
get
21+
{
22+
var remote = innerCollection[name];
23+
return remote is null ? null : new Remote(remote);
24+
}
25+
}
26+
}
27+
}

src/GitVersionCore/Git/IGitRepository.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public interface IGitRepository : IDisposable
1313
IReferenceCollection Refs { get; }
1414
IBranchCollection Branches { get; }
1515
ICommitCollection Commits { get; }
16+
IRemoteCollection Remotes { get; }
1617

1718
IGitRepository CreateNew(string gitRootPath);
1819

1920
int GetNumberOfUncommittedChanges();
2021
string ShortenObjectId(ICommit commit);
2122

22-
bool GitRepoHasMatchingRemote(string targetUrl);
2323
void CleanupDuplicateOrigin(string gitRootPath, string remoteName);
2424
bool GetMatchingCommitBranch(ICommit baseVersionSource, IBranch branch, ICommit firstMatchingCommit);
2525
IRemote EnsureOnlyOneRemoteIsDefined();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Collections.Generic;
2+
3+
namespace GitVersion
4+
{
5+
public interface IRemoteCollection : IEnumerable<IRemote>
6+
{
7+
IRemote this[string name] { get; }
8+
}
9+
}

0 commit comments

Comments
 (0)