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

Commit db41ef9

Browse files
committed
Get rid of LocalRepositoryModelFactory
We can now use GitService as a LocalRepositoryMode factory.
1 parent a47af2b commit db41ef9

File tree

9 files changed

+44
-67
lines changed

9 files changed

+44
-67
lines changed

src/GitHub.Exports/Models/ILocalRepositoryModelFactory.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/GitHub.TeamFoundation.14/GitHub.TeamFoundation.14.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@
163163
<Compile Include="Home\ForkNavigationItem.cs" />
164164
<Compile Include="RegistryHelper.cs" />
165165
<Compile Include="Services\VSGitServices.cs" />
166-
<Compile Include="Services\LocalRepositoryModelFactory.cs" />
167166
<Compile Include="Services\VSUIContextFactory.cs" />
168167
<Compile Include="Settings.cs" />
169168
<Compile Include="Base\EnsureLoggedInSection.cs" />

src/GitHub.TeamFoundation.14/Services/LocalRepositoryModelFactory.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/GitHub.TeamFoundation.14/Services/VSGitExt.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,26 @@ public class VSGitExt : IVSGitExt
2727
static readonly ILogger log = LogManager.ForContext<VSGitExt>();
2828

2929
readonly IServiceProvider serviceProvider;
30-
readonly ILocalRepositoryModelFactory repositoryFactory;
30+
readonly IGitService gitService;
3131
readonly object refreshLock = new object();
3232

33-
IGitExt gitService;
33+
IGitExt gitExt;
3434
IReadOnlyList<ILocalRepositoryModel> activeRepositories;
3535

36-
public VSGitExt(IServiceProvider serviceProvider)
37-
: this(serviceProvider, new VSUIContextFactory(), new LocalRepositoryModelFactory(), ThreadHelper.JoinableTaskContext)
36+
public VSGitExt(IServiceProvider serviceProvider, IGitService gitService)
37+
: this(serviceProvider, new VSUIContextFactory(), gitService, ThreadHelper.JoinableTaskContext)
3838
{
3939
}
4040

41-
public VSGitExt(IServiceProvider serviceProvider, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory,
41+
public VSGitExt(IServiceProvider serviceProvider, IVSUIContextFactory factory, IGitService gitService,
4242
JoinableTaskContext joinableTaskContext)
4343
{
4444
JoinableTaskCollection = joinableTaskContext.CreateCollection();
4545
JoinableTaskCollection.DisplayName = nameof(VSGitExt);
4646
JoinableTaskFactory = joinableTaskContext.CreateFactory(JoinableTaskCollection);
4747

4848
this.serviceProvider = serviceProvider;
49-
this.repositoryFactory = repositoryFactory;
49+
this.gitService = gitService;
5050

5151
// Start with empty array until we have a chance to initialize.
5252
ActiveRepositories = Array.Empty<ILocalRepositoryModel>();
@@ -64,7 +64,7 @@ public VSGitExt(IServiceProvider serviceProvider, IVSUIContextFactory factory, I
6464

6565
async Task InitializeAsync()
6666
{
67-
gitService = await GetServiceAsync<IGitExt>();
67+
gitExt = await GetServiceAsync<IGitExt>();
6868
if (gitService == null)
6969
{
7070
log.Error("Couldn't find IGitExt service");
@@ -74,9 +74,9 @@ async Task InitializeAsync()
7474
// Refresh on background thread
7575
await Task.Run(() => RefreshActiveRepositories());
7676

77-
gitService.PropertyChanged += (s, e) =>
77+
gitExt.PropertyChanged += (s, e) =>
7878
{
79-
if (e.PropertyName == nameof(gitService.ActiveRepositories))
79+
if (e.PropertyName == nameof(gitExt.ActiveRepositories))
8080
{
8181
RefreshActiveRepositories();
8282
}
@@ -91,10 +91,10 @@ public void RefreshActiveRepositories()
9191
{
9292
log.Debug(
9393
"IGitExt.ActiveRepositories (#{Id}) returned {Repositories}",
94-
gitService.GetHashCode(),
95-
gitService.ActiveRepositories.Select(x => x.RepositoryPath));
94+
gitExt.GetHashCode(),
95+
gitExt.ActiveRepositories.Select(x => x.RepositoryPath));
9696

97-
ActiveRepositories = gitService?.ActiveRepositories.Select(x => repositoryFactory.Create(x.RepositoryPath)).ToList();
97+
ActiveRepositories = gitExt?.ActiveRepositories.Select(x => gitService.CreateLocalRepositoryModel(x.RepositoryPath)).ToList();
9898
}
9999
}
100100
catch (Exception e)

src/GitHub.TeamFoundation.15/GitHub.TeamFoundation.15.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@
180180
<Compile Include="..\GitHub.TeamFoundation.14\RegistryHelper.cs">
181181
<Link>RegistryHelper.cs</Link>
182182
</Compile>
183-
<Compile Include="..\GitHub.TeamFoundation.14\Services\LocalRepositoryModelFactory.cs">
184-
<Link>Services\LocalRepositoryModelFactory.cs</Link>
185-
</Compile>
186183
<Compile Include="..\GitHub.TeamFoundation.14\Services\VSGitExt.cs">
187184
<Link>Services\VSGitExt.cs</Link>
188185
</Compile>

src/GitHub.TeamFoundation.16/GitHub.TeamFoundation.16.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@
180180
<Compile Include="..\GitHub.TeamFoundation.14\RegistryHelper.cs">
181181
<Link>RegistryHelper.cs</Link>
182182
</Compile>
183-
<Compile Include="..\GitHub.TeamFoundation.14\Services\LocalRepositoryModelFactory.cs">
184-
<Link>Services\LocalRepositoryModelFactory.cs</Link>
185-
</Compile>
186183
<Compile Include="..\GitHub.TeamFoundation.14\Services\VSGitExt.cs">
187184
<Link>Services\VSGitExt.cs</Link>
188185
</Compile>

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
299299
else if (serviceType == typeof(IVSGitExt))
300300
{
301301
var vsVersion = ApplicationInfo.GetHostVersionInfo().FileMajorPart;
302-
return new VSGitExtFactory(vsVersion, this).Create();
302+
return new VSGitExtFactory(vsVersion, this, GitService.GitServiceHelper).Create();
303303
}
304304
else if (serviceType == typeof(IGitHubToolWindowManager))
305305
{

src/GitHub.VisualStudio/Services/VSGitExtFactory.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,25 @@ public class VSGitExtFactory
1717

1818
readonly int vsVersion;
1919
readonly IServiceProvider serviceProvider;
20+
readonly IGitService gitService;
2021

21-
public VSGitExtFactory(int vsVersion, IServiceProvider serviceProvider)
22+
public VSGitExtFactory(int vsVersion, IServiceProvider serviceProvider, IGitService gitService)
2223
{
2324
this.vsVersion = vsVersion;
2425
this.serviceProvider = serviceProvider;
26+
this.gitService = gitService;
2527
}
2628

2729
public IVSGitExt Create()
2830
{
2931
switch (vsVersion)
3032
{
3133
case 14:
32-
return Create(() => new VSGitExt14(serviceProvider));
34+
return Create(() => new VSGitExt14(serviceProvider, gitService));
3335
case 15:
34-
return Create(() => new VSGitExt15(serviceProvider));
36+
return Create(() => new VSGitExt15(serviceProvider, gitService));
3537
case 16:
36-
return Create(() => new VSGitExt16(serviceProvider));
38+
return Create(() => new VSGitExt16(serviceProvider, gitService));
3739
default:
3840
log.Error("There is no IVSGitExt implementation for DTE version {Version}", vsVersion);
3941
return null;

test/GitHub.TeamFoundation.UnitTests/VSGitExtTests.cs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
using NUnit.Framework;
1111
using NSubstitute;
1212
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
13-
using Microsoft.VisualStudio.Shell;
1413
using Microsoft.VisualStudio.Threading;
1514
using Task = System.Threading.Tasks.Task;
1615
using static Microsoft.VisualStudio.VSConstants;
16+
using GitHub.Primitives;
17+
using LibGit2Sharp;
18+
using System.Threading.Tasks;
1719

1820
public class VSGitExtTests
1921
{
@@ -149,41 +151,41 @@ public void RepositoryOpenContextNotActive_IsEmpty()
149151
public void RepositoryOpenIsActive_InitializeWithActiveRepositories()
150152
{
151153
var repoPath = "repoPath";
152-
var repoFactory = Substitute.For<ILocalRepositoryModelFactory>();
154+
var gitService = Substitute.For<IGitService>();
153155
var context = CreateVSUIContext(true);
154156
var gitExt = CreateGitExt(new[] { repoPath });
155-
var target = CreateVSGitExt(context, gitExt, repoFactory: repoFactory);
157+
var target = CreateVSGitExt(context, gitExt, gitService: gitService);
156158
target.JoinTillEmpty();
157159

158160
var activeRepositories = target.ActiveRepositories;
159161

160162
Assert.That(activeRepositories.Count, Is.EqualTo(1));
161-
repoFactory.Received(1).Create(repoPath);
163+
gitService.Received(1).CreateLocalRepositoryModel(repoPath);
162164
}
163165

164166
[Test]
165167
public void ExceptionRefreshingRepositories_ReturnsEmptyList()
166168
{
167169
var repoPath = "repoPath";
168-
var repoFactory = Substitute.For<ILocalRepositoryModelFactory>();
169-
repoFactory.Create(repoPath).ReturnsForAnyArgs(x => { throw new Exception("Boom!"); });
170+
var gitService = Substitute.For<IGitService>();
171+
gitService.CreateLocalRepositoryModel(repoPath).ReturnsForAnyArgs(x => { throw new Exception("Boom!"); });
170172
var context = CreateVSUIContext(true);
171173
var gitExt = CreateGitExt(new[] { repoPath });
172-
var target = CreateVSGitExt(context, gitExt, repoFactory: repoFactory);
174+
var target = CreateVSGitExt(context, gitExt, gitService: gitService);
173175
target.JoinTillEmpty();
174176

175177
var activeRepositories = target.ActiveRepositories;
176178

177-
repoFactory.Received(1).Create(repoPath);
179+
gitService.Received(1).CreateLocalRepositoryModel(repoPath);
178180
Assert.That(activeRepositories.Count, Is.EqualTo(0));
179181
}
180182

181183
[Test]
182184
public async Task ActiveRepositoriesChangedOrderingShouldBeCorrectAcrossThreads()
183185
{
184186
var gitExt = new MockGitExt();
185-
var repoFactory = new MockRepositoryFactory();
186-
var target = CreateVSGitExt(gitExt: gitExt, repoFactory: repoFactory);
187+
var gitService = new MockGitService();
188+
var target = CreateVSGitExt(gitExt: gitExt, gitService: gitService);
187189
var activeRepositories1 = CreateActiveRepositories("repo1");
188190
var activeRepositories2 = CreateActiveRepositories("repo2");
189191
var task1 = Task.Run(() => gitExt.ActiveRepositories = activeRepositories1);
@@ -211,18 +213,18 @@ static IReadOnlyList<IGitRepositoryInfo> CreateActiveRepositories(params string[
211213
}
212214

213215
static VSGitExt CreateVSGitExt(IVSUIContext context = null, IGitExt gitExt = null, IServiceProvider sp = null,
214-
ILocalRepositoryModelFactory repoFactory = null, JoinableTaskContext joinableTaskContext = null, string contextGuidString = null)
216+
IGitService gitService = null, JoinableTaskContext joinableTaskContext = null, string contextGuidString = null)
215217
{
216218
context = context ?? CreateVSUIContext(true);
217219
gitExt = gitExt ?? CreateGitExt();
218220
var contextGuid = new Guid(contextGuidString ?? Guids.GitSccProviderId);
219221
sp = sp ?? Substitute.For<IServiceProvider>();
220-
repoFactory = repoFactory ?? Substitute.For<ILocalRepositoryModelFactory>();
222+
gitService = gitService ?? Substitute.For<IGitService>();
221223
joinableTaskContext = joinableTaskContext ?? new JoinableTaskContext();
222224
var factory = Substitute.For<IVSUIContextFactory>();
223225
factory.GetUIContext(contextGuid).Returns(context);
224226
sp.GetService(typeof(IGitExt)).Returns(gitExt);
225-
var vsGitExt = new VSGitExt(sp, factory, repoFactory, joinableTaskContext);
227+
var vsGitExt = new VSGitExt(sp, factory, gitService, joinableTaskContext);
226228
vsGitExt.JoinTillEmpty();
227229
return vsGitExt;
228230
}
@@ -291,9 +293,9 @@ public IReadOnlyList<IGitRepositoryInfo> ActiveRepositories
291293
public event PropertyChangedEventHandler PropertyChanged;
292294
}
293295

294-
class MockRepositoryFactory : ILocalRepositoryModelFactory
296+
class MockGitService : IGitService
295297
{
296-
public ILocalRepositoryModel Create(string localPath)
298+
public ILocalRepositoryModel CreateLocalRepositoryModel(string localPath)
297299
{
298300
var result = Substitute.For<ILocalRepositoryModel>();
299301
result.LocalPath.Returns(localPath);
@@ -308,5 +310,13 @@ public ILocalRepositoryModel Create(string localPath)
308310

309311
return result;
310312
}
313+
314+
public IBranch CreateCurrentBranchModel(ILocalRepositoryModel model) => throw new NotImplementedException();
315+
public Task<string> GetLatestPushedSha(string path, string remote = "origin") => throw new NotImplementedException();
316+
public UriString GetRemoteUri(IRepository repo, string remote = "origin") => throw new NotImplementedException();
317+
public IRepository GetRepository(string path) => throw new NotImplementedException();
318+
public UriString GetUri(IRepository repository, string remote = "origin") => throw new NotImplementedException();
319+
public UriString GetUri(string path, string remote = "origin") => throw new NotImplementedException();
320+
public void Refresh(ILocalRepositoryModel localRepositoryModel) => throw new NotImplementedException();
311321
}
312322
}

0 commit comments

Comments
 (0)