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,21 @@ 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 , IGitService gitService = null )
28- : base ( name , cloneUrl , gitService )
29+ public LocalRepositoryModel ( string name , UriString cloneUrl , string localPath , IGitService gitService )
30+ : base ( name , cloneUrl )
2931 {
3032 Guard . ArgumentNotEmptyString ( localPath , nameof ( localPath ) ) ;
33+ Guard . ArgumentNotNull ( gitService , nameof ( gitService ) ) ;
3134
35+ this . gitService = gitService ;
3236 LocalPath = localPath ;
3337 Icon = Octicon . repo ;
3438 }
@@ -37,9 +41,12 @@ public LocalRepositoryModel(string name, UriString cloneUrl, string localPath, I
3741 /// Initializes a new instance of the <see cref="LocalRepositoryModel"/> class.
3842 /// </summary>
3943 /// <param name="path">The repository's local path.</param>
40- public LocalRepositoryModel ( string path , IGitService gitService = null )
44+ public LocalRepositoryModel ( string path , IGitService gitService )
4145 : base ( path , gitService )
4246 {
47+ Guard . ArgumentNotNull ( gitService , nameof ( gitService ) ) ;
48+
49+ this . gitService = gitService ;
4350 LocalPath = path ;
4451 Icon = Octicon . repo ;
4552 }
@@ -51,7 +58,7 @@ public void Refresh()
5158 {
5259 if ( LocalPath == null )
5360 return ;
54- CloneUrl = GitService . GetUri ( LocalPath ) ;
61+ CloneUrl = gitService . GetUri ( LocalPath ) ;
5562 }
5663
5764 /// <summary>
@@ -68,7 +75,7 @@ public async Task<UriString> GenerateUrl(LinkType linkType, string path = null,
6875 if ( CloneUrl == null )
6976 return null ;
7077
71- var sha = await GitService . GetLatestPushedSha ( path ?? LocalPath ) ;
78+ var sha = await gitService . GetLatestPushedSha ( path ?? LocalPath ) ;
7279 // this also incidentally checks whether the repo has a valid LocalPath
7380 if ( String . IsNullOrEmpty ( sha ) )
7481 return CloneUrl . ToRepositoryUrl ( ) . AbsoluteUri ;
@@ -157,7 +164,7 @@ public string HeadSha
157164 {
158165 get
159166 {
160- using ( var repo = GitService . GetRepository ( LocalPath ) )
167+ using ( var repo = gitService . GetRepository ( LocalPath ) )
161168 {
162169 return repo ? . Commits . FirstOrDefault ( ) ? . Sha ?? string . Empty ;
163170 }
@@ -172,7 +179,7 @@ public IBranch CurrentBranch
172179 get
173180 {
174181 // BranchModel doesn't keep a reference to Repository
175- using ( var repo = GitService . GetRepository ( LocalPath ) )
182+ using ( var repo = gitService . GetRepository ( LocalPath ) )
176183 {
177184 return new BranchModel ( repo ? . Head , this ) ;
178185 }
0 commit comments