55using System . Linq ;
66using GitHub . Primitives ;
77using GitHub . UI ;
8+ using GitHub . Exports ;
89using GitHub . Services ;
910using GitHub . Extensions ;
1011using System . Threading . Tasks ;
11- using GitHub . Exports ;
1212
1313namespace GitHub . Models
1414{
@@ -18,17 +18,22 @@ namespace GitHub.Models
1818 [ DebuggerDisplay ( "{DebuggerDisplay,nq}" ) ]
1919 public class LocalRepositoryModel : RepositoryModel , ILocalRepositoryModel , IEquatable < LocalRepositoryModel >
2020 {
21+ readonly IGitService gitService ;
22+
2123 /// <summary>
2224 /// Initializes a new instance of the <see cref="LocalRepositoryModel"/> class.
2325 /// </summary>
2426 /// <param name="name">The repository name.</param>
2527 /// <param name="cloneUrl">The repository's clone URL.</param>
2628 /// <param name="localPath">The repository's local path.</param>
27- public LocalRepositoryModel ( string name , UriString cloneUrl , string localPath )
29+ /// <param name="gitService">The service used to refresh the repository's URL.</param>
30+ public LocalRepositoryModel ( string name , UriString cloneUrl , string localPath , IGitService gitService )
2831 : base ( name , cloneUrl )
2932 {
3033 Guard . ArgumentNotEmptyString ( localPath , nameof ( localPath ) ) ;
34+ Guard . ArgumentNotNull ( gitService , nameof ( gitService ) ) ;
3135
36+ this . gitService = gitService ;
3237 LocalPath = localPath ;
3338 Icon = Octicon . repo ;
3439 }
@@ -37,9 +42,13 @@ public LocalRepositoryModel(string name, UriString cloneUrl, string localPath)
3742 /// Initializes a new instance of the <see cref="LocalRepositoryModel"/> class.
3843 /// </summary>
3944 /// <param name="path">The repository's local path.</param>
40- public LocalRepositoryModel ( string path )
41- : base ( path )
45+ /// <param name="gitService">The service used to find the repository's URL.</param>
46+ public LocalRepositoryModel ( string path , IGitService gitService )
47+ : base ( path , gitService )
4248 {
49+ Guard . ArgumentNotNull ( gitService , nameof ( gitService ) ) ;
50+
51+ this . gitService = gitService ;
4352 LocalPath = path ;
4453 Icon = Octicon . repo ;
4554 }
@@ -51,7 +60,7 @@ public void Refresh()
5160 {
5261 if ( LocalPath == null )
5362 return ;
54- CloneUrl = GitService . GitServiceHelper . GetUri ( LocalPath ) ;
63+ CloneUrl = gitService . GetUri ( LocalPath ) ;
5564 }
5665
5766 /// <summary>
@@ -68,7 +77,7 @@ public async Task<UriString> GenerateUrl(LinkType linkType, string path = null,
6877 if ( CloneUrl == null )
6978 return null ;
7079
71- var sha = await GitService . GitServiceHelper . GetLatestPushedSha ( path ?? LocalPath ) ;
80+ var sha = await gitService . GetLatestPushedSha ( path ?? LocalPath ) ;
7281 // this also incidentally checks whether the repo has a valid LocalPath
7382 if ( String . IsNullOrEmpty ( sha ) )
7483 return CloneUrl . ToRepositoryUrl ( ) . AbsoluteUri ;
@@ -157,7 +166,7 @@ public string HeadSha
157166 {
158167 get
159168 {
160- using ( var repo = GitService . GitServiceHelper . GetRepository ( LocalPath ) )
169+ using ( var repo = gitService . GetRepository ( LocalPath ) )
161170 {
162171 return repo ? . Commits . FirstOrDefault ( ) ? . Sha ?? string . Empty ;
163172 }
@@ -172,9 +181,9 @@ public IBranch CurrentBranch
172181 get
173182 {
174183 // BranchModel doesn't keep a reference to Repository
175- using ( var repo = GitService . GitServiceHelper . GetRepository ( LocalPath ) )
184+ using ( var repo = gitService . GetRepository ( LocalPath ) )
176185 {
177- return new BranchModel ( repo ? . Head , this ) ;
186+ return new BranchModel ( repo ? . Head , this , gitService ) ;
178187 }
179188 }
180189 }
0 commit comments