|
11 | 11 | using Microsoft.VisualStudio.Shell.Interop; |
12 | 12 | using Microsoft.Win32; |
13 | 13 | using System.Diagnostics; |
| 14 | +using Microsoft.TeamFoundation.Git.Controls.Extensibility; |
| 15 | +using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility; |
14 | 16 |
|
15 | 17 | namespace GitHub.Services |
16 | 18 | { |
17 | | - public interface IVSServices |
18 | | - { |
19 | | - string GetLocalClonePathFromGitProvider(); |
20 | | - void Clone(string cloneUrl, string clonePath, bool recurseSubmodules); |
21 | | - string GetActiveRepoPath(); |
22 | | - LibGit2Sharp.IRepository GetActiveRepo(); |
23 | | - IEnumerable<ISimpleRepositoryModel> GetKnownRepositories(); |
24 | | - string SetDefaultProjectPath(string path); |
25 | | - |
26 | | - void ActivityLogMessage(string message); |
27 | | - void ActivityLogWarning(string message); |
28 | | - void ActivityLogError(string message); |
29 | | - } |
30 | | - |
31 | 19 | [Export(typeof(IVSServices))] |
32 | 20 | [PartCreationPolicy(CreationPolicy.Shared)] |
33 | 21 | public class VSServices : IVSServices |
@@ -61,37 +49,30 @@ public string GetLocalClonePathFromGitProvider() |
61 | 49 |
|
62 | 50 | public void Clone(string cloneUrl, string clonePath, bool recurseSubmodules) |
63 | 51 | { |
64 | | - var gitExt = serviceProvider.TryGetService("Microsoft.TeamFoundation.Git.Controls.Extensibility.IGitRepositoriesExt, Microsoft.TeamFoundation.Git.Controls"); |
65 | | - var cloneOptionsType = Type.GetType("Microsoft.TeamFoundation.Git.Controls.Extensibility.CloneOptions, Microsoft.TeamFoundation.Git.Controls"); |
66 | | - var cloneMethod = gitExt.GetType().GetMethod("Clone", new Type[] { typeof(string), typeof(string), cloneOptionsType }); |
67 | | - cloneMethod.Invoke(gitExt, new object[] { cloneUrl, clonePath, recurseSubmodules ? 1 : 0 }); |
| 52 | + var gitExt = serviceProvider.GetService<IGitRepositoriesExt>(); |
| 53 | + gitExt.Clone(cloneUrl, clonePath, recurseSubmodules ? CloneOptions.RecurseSubmodule : CloneOptions.None); |
68 | 54 | } |
69 | 55 |
|
70 | | - object GetRepoFromVS() |
| 56 | + IGitRepositoryInfo GetRepoFromVS() |
71 | 57 | { |
72 | | - var gitExt = serviceProvider.TryGetService("Microsoft.VisualStudio.TeamFoundation.Git.Extensibility.IGitExt, Microsoft.TeamFoundation.Git.Provider"); |
73 | | - var prop = gitExt?.GetType().GetProperty("ActiveRepositories"); |
74 | | - var activeRepositories = prop?.GetValue(gitExt) as IEnumerable; |
75 | | - var e = activeRepositories?.GetEnumerator(); |
76 | | - if (e?.MoveNext() ?? false) |
77 | | - return e.Current; |
78 | | - return null; |
| 58 | + var gitExt = serviceProvider.GetService<IGitExt>(); |
| 59 | + return gitExt.ActiveRepositories.FirstOrDefault(); |
79 | 60 | } |
80 | 61 |
|
81 | 62 | public LibGit2Sharp.IRepository GetActiveRepo() |
82 | 63 | { |
83 | 64 | var repo = GetRepoFromVS(); |
84 | | - if (repo != null) |
85 | | - return serviceProvider.GetService<IGitService>().GetRepo(repo.GetType().GetProperty("RepositoryPath").GetValue(repo) as string); |
86 | | - return serviceProvider.GetSolution().GetRepoFromSolution(); |
| 65 | + return repo != null |
| 66 | + ? serviceProvider.GetService<IGitService>().GetRepo(repo.RepositoryPath) |
| 67 | + : serviceProvider.GetSolution().GetRepoFromSolution(); |
87 | 68 | } |
88 | 69 |
|
89 | 70 | public string GetActiveRepoPath() |
90 | 71 | { |
91 | 72 | string ret = null; |
92 | 73 | var repo = GetRepoFromVS(); |
93 | 74 | if (repo != null) |
94 | | - ret = repo.GetType().GetProperty("RepositoryPath")?.GetValue(repo) as string; |
| 75 | + ret = repo.RepositoryPath; |
95 | 76 | if (ret == null) |
96 | 77 | ret = serviceProvider.GetSolution().GetRepoFromSolution()?.Info?.Path; |
97 | 78 | return ret ?? String.Empty; |
|
0 commit comments