Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit b1db91f

Browse files
committed
Remove IGitService dependency from BranchModel
Removed dead and buggy code from BranchModel constructorer. We construct BranchModel from the HEAD branch, which isn't a remote branch. No need to construct a RepositoryModel from a URL.
1 parent bccfbd0 commit b1db91f

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/GitHub.Exports/Models/BranchModel.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
using System;
22
using System.Globalization;
3-
using GitHub.Services;
43

54
namespace GitHub.Models
65
{
76
public class BranchModel : IBranch
87
{
8+
public BranchModel(string name, IRepositoryModel repo, string sha, bool isTracking, string trackedSha) :
9+
this(name, repo)
10+
{
11+
IsTracking = isTracking;
12+
Sha = sha;
13+
TrackedSha = trackedSha;
14+
}
15+
916
public BranchModel(string name, IRepositoryModel repo)
1017
{
1118
Extensions.Guard.ArgumentNotEmptyString(name, nameof(name));
@@ -26,21 +33,6 @@ public BranchModel(Octokit.Branch branch, IRepositoryModel repo)
2633
Id = String.Format(CultureInfo.InvariantCulture, "{0}/{1}", Repository.Owner, Name);
2734
}
2835

29-
public BranchModel(LibGit2Sharp.Branch branch, IRepositoryModel repo, IGitService gitService)
30-
{
31-
Extensions.Guard.ArgumentNotNull(branch, nameof(branch));
32-
Extensions.Guard.ArgumentNotNull(repo, nameof(repo));
33-
Name = DisplayName = branch.FriendlyName;
34-
#pragma warning disable 0618 // TODO: Replace `Branch.Remote` with `Repository.Network.Remotes[branch.RemoteName]`.
35-
// NOTE: This method expects a localPath not a URL!
36-
Repository = branch.IsRemote ? gitService.CreateLocalRepositoryModel(branch.Remote.Url) : repo;
37-
#pragma warning restore 0618
38-
IsTracking = branch.IsTracking;
39-
Sha = branch.Tip?.Sha;
40-
TrackedSha = branch.TrackedBranch?.Tip?.Sha;
41-
Id = String.Format(CultureInfo.InvariantCulture, "{0}/{1}", Repository.Owner, Name);
42-
}
43-
4436
public string Id { get; private set; }
4537
public string Name { get; private set; }
4638
public IRepositoryModel Repository { get; private set; }

src/GitHub.Exports/Services/GitService.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ public IBranch GetBranch(ILocalRepositoryModel model)
5757
var localPath = model.LocalPath;
5858
using (var repo = GetRepository(localPath))
5959
{
60-
var headBranch = repo?.Head;
61-
if (headBranch == null)
60+
var branch = repo?.Head;
61+
if (branch == null)
6262
{
6363
return null;
6464
}
6565

66-
// BranchModel doesn't keep a reference to Repository
67-
return new BranchModel(headBranch, model, this);
66+
return new BranchModel(
67+
name: branch.FriendlyName,
68+
repo: model,
69+
sha: branch.Tip?.Sha,
70+
isTracking: branch.IsTracking,
71+
trackedSha: branch.TrackedBranch?.Tip?.Sha);
6872
}
6973
}
7074

0 commit comments

Comments
 (0)