|
| 1 | +using GitVersion.Extensions; |
| 2 | +using LibGit2Sharp; |
| 3 | + |
1 | 4 | namespace GitVersion;
|
2 | 5 |
|
3 | 6 | internal sealed class BranchCollection : IBranchCollection
|
4 | 7 | {
|
5 | 8 | private readonly LibGit2Sharp.BranchCollection innerCollection;
|
6 |
| - internal BranchCollection(LibGit2Sharp.BranchCollection collection) => this.innerCollection = collection; |
7 | 9 |
|
8 |
| - public IEnumerator<IBranch> GetEnumerator() => this.innerCollection.Select(branch => new Branch(branch)).GetEnumerator(); |
| 10 | + internal BranchCollection(LibGit2Sharp.BranchCollection collection) |
| 11 | + => this.innerCollection = collection.NotNull(); |
| 12 | + |
| 13 | + public IEnumerator<IBranch> GetEnumerator() |
| 14 | + => this.innerCollection.Select(branch => new Branch(branch)).GetEnumerator(); |
| 15 | + |
9 | 16 | IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
| 17 | + |
10 | 18 | public IBranch? this[string name]
|
11 | 19 | {
|
12 | 20 | get
|
13 | 21 | {
|
| 22 | + name = name.NotNull(); |
14 | 23 | var branch = this.innerCollection[name];
|
15 | 24 | return branch is null ? null : new Branch(branch);
|
16 | 25 | }
|
17 | 26 | }
|
18 | 27 |
|
19 |
| - public IEnumerable<IBranch> ExcludeBranches(IEnumerable<IBranch> branchesToExclude) => |
20 |
| - this.Where(b => branchesToExclude.All(bte => !b.Equals(bte))); |
21 |
| - public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName) => |
22 |
| - this.innerCollection.Update((Branch)branch, b => b.TrackedBranch = remoteTrackingReferenceName); |
| 28 | + public IEnumerable<IBranch> ExcludeBranches(IEnumerable<IBranch> branchesToExclude) |
| 29 | + { |
| 30 | + branchesToExclude = branchesToExclude.NotNull(); |
| 31 | + |
| 32 | + bool BranchIsNotExcluded(IBranch branch) |
| 33 | + => branchesToExclude.All(branchToExclude => !branch.Equals(branchToExclude)); |
| 34 | + |
| 35 | + return this.Where(BranchIsNotExcluded); |
| 36 | + } |
| 37 | + |
| 38 | + public void UpdateTrackedBranch(IBranch branch, string remoteTrackingReferenceName) |
| 39 | + { |
| 40 | + var branchToUpdate = (Branch)branch.NotNull(); |
| 41 | + |
| 42 | + void Updater(BranchUpdater branchUpdater) => |
| 43 | + branchUpdater.TrackedBranch = remoteTrackingReferenceName; |
| 44 | + |
| 45 | + this.innerCollection.Update(branchToUpdate, Updater); |
| 46 | + } |
23 | 47 | }
|
0 commit comments