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

Commit ef0a40e

Browse files
committed
Move IGitService to its own file and document it
I documented all the methods.
1 parent 56b36e5 commit ef0a40e

File tree

3 files changed

+126
-25
lines changed

3 files changed

+126
-25
lines changed

src/GitHub.Exports/GitHub.Exports.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
<Compile Include="Helpers\NotificationAwareObject.cs" />
113113
<Compile Include="Services\Connection.cs" />
114114
<Compile Include="Services\GitService.cs" />
115+
<Compile Include="Services\IGitService.cs" />
115116
<Compile Include="Services\ITeamExplorerServiceHolder.cs" />
116117
<Compile Include="Services\Logger.cs" />
117118
<Compile Include="Services\Services.cs" />

src/GitHub.Exports/Services/GitService.cs

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,89 @@
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;
62
using System.ComponentModel.Composition;
73
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;
107

118
namespace GitHub.Services
129
{
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-
2210
[Export(typeof(IVSServices))]
2311
[PartCreationPolicy(CreationPolicy.Shared)]
2412
public class GitService : IGitService
2513
{
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)
2721
{
28-
return UriString.ToUriString(GetUriFromRepository(repo)?.ToRepositoryUrl());
22+
return UriString.ToUriString(GetUriFromRepository(repository)?.ToRepositoryUrl());
2923
}
3024

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>
3135
public UriString GetUri(string path)
3236
{
3337
return GetUri(GetRepo(path));
3438
}
3539

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>
3651
public UriString GetUri(IGitRepositoryInfo repoInfo)
3752
{
3853
return GetUri(GetRepo(repoInfo));
3954
}
4055

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+
4168
public IRepository GetRepo(IGitRepositoryInfo repoInfo)
4269
{
43-
var repoPath = Repository.Discover(repoInfo?.RepositoryPath);
44-
if (repoPath == null)
45-
return null;
46-
return new Repository(repoPath);
70+
return GetRepo(repoInfo?.RepositoryPath);
4771
}
4872

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>
4983
public IRepository GetRepo(string path)
5084
{
5185
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);
5587
}
5688

5789
internal static UriString GetUriFromRepository(IRepository repo)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using GitHub.Primitives;
2+
using LibGit2Sharp;
3+
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
4+
5+
namespace GitHub.Services
6+
{
7+
public interface IGitService
8+
{
9+
/// <summary>
10+
/// Returns the URL of the remote named "origin" for the specified <see cref="repository"/>. If the repository
11+
/// is null or no remote named origin exists, this method returns null
12+
/// </summary>
13+
/// <param name="repository">The repository to look at for the remote.</param>
14+
/// <returns>A <see cref="UriString"/> representing the origin or null if none found.</returns>
15+
UriString GetUri(IRepository repository);
16+
17+
/// <summary>
18+
/// Probes for a git repository and if one is found, returns a <see cref="UriString"/> for the repository's
19+
/// remote named "origin" if one is found
20+
/// </summary>
21+
/// <remarks>
22+
/// The lookup checks to see if the specified <paramref name="path"/> is a repository. If it's not, it then
23+
/// walks up the parent directories until it either finds a repository, or reaches the root disk.
24+
/// </remarks>
25+
/// <param name="path">The path to start probing</param>
26+
/// <returns>A <see cref="UriString"/> representing the origin or null if none found.</returns>
27+
UriString GetUri(string path);
28+
29+
/// <summary>
30+
/// Probes for a git repository and if one is found, returns a <see cref="UriString"/> for the repository's
31+
/// remote named "origin" if one is found
32+
/// </summary>
33+
/// <remarks>
34+
/// The lookup checks to see if the path specified by the RepositoryPath property of the specified
35+
/// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it
36+
/// either finds a repository, or reaches the root disk.
37+
/// </remarks>
38+
/// <param name="repoInfo">The repository information containing the path to start probing</param>
39+
/// <returns>A <see cref="UriString"/> representing the origin or null if none found.</returns>
40+
UriString GetUri(IGitRepositoryInfo repoInfo);
41+
42+
/// <summary>
43+
/// Probes for a git repository and if one is found, returns a <see cref="IRepository"/> instance for the
44+
/// repository.
45+
/// </summary>
46+
/// <remarks>
47+
/// The lookup checks to see if the path specified by the RepositoryPath property of the specified
48+
/// <see cref="repoInfo"/> is a repository. If it's not, it then walks up the parent directories until it
49+
/// either finds a repository, or reaches the root disk.
50+
/// </remarks>
51+
/// <param name="repoInfo">The repository information containing the path to start probing</param>
52+
/// <returns>An instance of <see cref="IRepository"/> or null</returns>
53+
54+
IRepository GetRepo(IGitRepositoryInfo repoInfo);
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 specified <paramref name="path"/> is a repository. If it's not, it then
62+
/// walks up the parent directories until it either finds a repository, or reaches the root disk.
63+
/// </remarks>
64+
/// <param name="path">The path to start probing</param>
65+
/// <returns>An instance of <see cref="IRepository"/> or null</returns>
66+
IRepository GetRepo(string path);
67+
}
68+
}

0 commit comments

Comments
 (0)