|
1 | | -using GitHub.Primitives; |
2 | | -using LibGit2Sharp; |
3 | | -using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility; |
4 | | -using System; |
5 | | -using System.Collections.Generic; |
| 1 | +using System; |
6 | 2 | using System.ComponentModel.Composition; |
7 | 3 | using System.Linq; |
8 | | -using System.Text; |
9 | | -using System.Threading.Tasks; |
| 4 | +using GitHub.Primitives; |
| 5 | +using LibGit2Sharp; |
| 6 | +using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility; |
10 | 7 |
|
11 | 8 | namespace GitHub.Services |
12 | 9 | { |
13 | | - public interface IGitService |
14 | | - { |
15 | | - UriString GetUri(string path); |
16 | | - UriString GetUri(IRepository repo); |
17 | | - UriString GetUri(IGitRepositoryInfo repoInfo); |
18 | | - IRepository GetRepo(IGitRepositoryInfo repoInfo); |
19 | | - IRepository GetRepo(string path); |
20 | | - } |
21 | | - |
22 | 10 | [Export(typeof(IVSServices))] |
23 | 11 | [PartCreationPolicy(CreationPolicy.Shared)] |
24 | 12 | public class GitService : IGitService |
25 | 13 | { |
26 | | - public UriString GetUri(IRepository repo) |
| 14 | + /// <summary> |
| 15 | + /// Returns the URL of the remote named "origin" for the specified <see cref="repository"/>. If the repository |
| 16 | + /// is null or no remote named origin exists, this method returns null |
| 17 | + /// </summary> |
| 18 | + /// <param name="repository">The repository to look at for the remote.</param> |
| 19 | + /// <returns>A <see cref="UriString"/> representing the origin or null if none found.</returns> |
| 20 | + public UriString GetUri(IRepository repository) |
27 | 21 | { |
28 | | - return UriString.ToUriString(GetUriFromRepository(repo)?.ToRepositoryUrl()); |
| 22 | + return UriString.ToUriString(GetUriFromRepository(repository)?.ToRepositoryUrl()); |
29 | 23 | } |
30 | 24 |
|
| 25 | + /// <summary> |
| 26 | + /// Probes for a git repository and if one is found, returns a <see cref="UriString"/> for the repository's |
| 27 | + /// remote named "origin" if one is found |
| 28 | + /// </summary> |
| 29 | + /// <remarks> |
| 30 | + /// The lookup checks to see if the specified <paramref name="path"/> is a repository. If it's not, it then |
| 31 | + /// walks up the parent directories until it either finds a repository, or reaches the root disk. |
| 32 | + /// </remarks> |
| 33 | + /// <param name="path">The path to start probing</param> |
| 34 | + /// <returns>A <see cref="UriString"/> representing the origin or null if none found.</returns> |
31 | 35 | public UriString GetUri(string path) |
32 | 36 | { |
33 | 37 | return GetUri(GetRepo(path)); |
34 | 38 | } |
35 | 39 |
|
| 40 | + /// <summary> |
| 41 | + /// Probes for a git repository and if one is found, returns a <see cref="UriString"/> for the repository's |
| 42 | + /// remote named "origin" if one is found |
| 43 | + /// </summary> |
| 44 | + /// <remarks> |
| 45 | + /// The lookup checks to see if the path specified by the RepositoryPath property of the specified |
| 46 | + /// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it |
| 47 | + /// either finds a repository, or reaches the root disk. |
| 48 | + /// </remarks> |
| 49 | + /// <param name="repoInfo">The repository information containing the path to start probing</param> |
| 50 | + /// <returns>A <see cref="UriString"/> representing the origin or null if none found.</returns> |
36 | 51 | public UriString GetUri(IGitRepositoryInfo repoInfo) |
37 | 52 | { |
38 | 53 | return GetUri(GetRepo(repoInfo)); |
39 | 54 | } |
40 | 55 |
|
| 56 | + /// <summary> |
| 57 | + /// Probes for a git repository and if one is found, returns a <see cref="IRepository"/> instance for the |
| 58 | + /// repository. |
| 59 | + /// </summary> |
| 60 | + /// <remarks> |
| 61 | + /// The lookup checks to see if the path specified by the RepositoryPath property of the specified |
| 62 | + /// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it |
| 63 | + /// either finds a repository, or reaches the root disk. |
| 64 | + /// </remarks> |
| 65 | + /// <param name="repoInfo">The repository information containing the path to start probing</param> |
| 66 | + /// <returns>An instance of <see cref="IRepository"/> or null</returns> |
| 67 | + |
41 | 68 | public IRepository GetRepo(IGitRepositoryInfo repoInfo) |
42 | 69 | { |
43 | | - var repoPath = Repository.Discover(repoInfo?.RepositoryPath); |
44 | | - if (repoPath == null) |
45 | | - return null; |
46 | | - return new Repository(repoPath); |
| 70 | + return GetRepo(repoInfo?.RepositoryPath); |
47 | 71 | } |
48 | 72 |
|
| 73 | + /// <summary> |
| 74 | + /// Probes for a git repository and if one is found, returns a <see cref="IRepository"/> instance for the |
| 75 | + /// repository. |
| 76 | + /// </summary> |
| 77 | + /// <remarks> |
| 78 | + /// The lookup checks to see if the specified <paramref name="path"/> is a repository. If it's not, it then |
| 79 | + /// walks up the parent directories until it either finds a repository, or reaches the root disk. |
| 80 | + /// </remarks> |
| 81 | + /// <param name="path">The path to start probing</param> |
| 82 | + /// <returns>An instance of <see cref="IRepository"/> or null</returns> |
49 | 83 | public IRepository GetRepo(string path) |
50 | 84 | { |
51 | 85 | var repoPath = Repository.Discover(path); |
52 | | - if (repoPath == null) |
53 | | - return null; |
54 | | - return new Repository(repoPath); |
| 86 | + return repoPath == null ? null : new Repository(repoPath); |
55 | 87 | } |
56 | 88 |
|
57 | 89 | internal static UriString GetUriFromRepository(IRepository repo) |
|
0 commit comments