1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
+ using System . Diagnostics . CodeAnalysis ;
4
5
using System . Linq ;
5
6
using System . Text . RegularExpressions ;
6
7
using System . Threading . Tasks ;
@@ -21,23 +22,43 @@ public class GitMissingOrNotGitRepoException : RepoInspectionException
21
22
/// <seealso cref="IRepoInspector"/>
22
23
public sealed class GitRepoInspector : IRepoInspector
23
24
{
25
+ #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
26
+ // TODO: Remove all of these enumerated permutations of the old optional args in 2.0.0
27
+ [ ExcludeFromCodeCoverage ]
28
+ [ Obsolete ( "Use FromPath(path, remote, log, commandRunner)" , error : false ) ]
29
+ public static Task < GitRepoInspector > FromPath ( string path , ILogger ? log , ICommandRunner ? commandRunner )
30
+ => FromPath ( path , "origin" , log , commandRunner ?? new SystemCommandRunner ( ) ) ;
31
+ [ ExcludeFromCodeCoverage ]
32
+ [ Obsolete ( "Use FromPath(path, remote, log, commandRunner)" , error : false ) ]
33
+ public static Task < GitRepoInspector > FromPath ( string path , ILogger ? log )
34
+ => FromPath ( path , "origin" , log , new SystemCommandRunner ( ) ) ;
35
+ [ ExcludeFromCodeCoverage ]
36
+ [ Obsolete ( "Use FromPath(path, remote, log, commandRunner)" , error : false ) ]
37
+ public static Task < GitRepoInspector > FromPath ( string path , ICommandRunner ? commandRunner )
38
+ => FromPath ( path , "origin" , null , commandRunner ?? new SystemCommandRunner ( ) ) ;
39
+ [ ExcludeFromCodeCoverage ]
40
+ [ Obsolete ( "Use FromPath(path, remote, log, commandRunner)" , error : false ) ]
41
+ public static Task < GitRepoInspector > FromPath ( string path )
42
+ => FromPath ( path , "origin" , null , new SystemCommandRunner ( ) ) ;
43
+ #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
44
+
24
45
/// <summary>
25
46
/// Creates an inspector from the specified path.
26
47
/// </summary>
27
48
/// <param name="path">The path of the Git repository.</param>
49
+ /// <param name="remote">The remote endpoint.</param>
28
50
/// <param name="log">A logger for diagnostics.</param>
29
- /// <param name="commandRunner">A command runner to use. Defaults to <see cref="SystemCommandRunner"/> if null is given. </param>
51
+ /// <param name="commandRunner">A command runner to use.</param>
30
52
/// <exception cref="GitMissingOrNotGitRepoException">Thrown if the path is not a Git repository.</exception>
31
53
/// <returns>A task containing the Git repo inspector.</returns>
32
- public static async Task < GitRepoInspector > FromPath ( string path , ILogger ? log = null , ICommandRunner ? commandRunner = null )
54
+ public static async Task < GitRepoInspector > FromPath ( string path , string remote , ILogger ? log , ICommandRunner commandRunner )
33
55
{
34
- commandRunner ??= new SystemCommandRunner ( ) ;
35
-
36
56
try
37
57
{
38
58
var ( root , _) = await commandRunner . Run ( path , "git" , new string [ ] { "rev-parse" , "--show-toplevel" } ) ;
39
59
var ret = new GitRepoInspector (
40
60
root ,
61
+ remote ,
41
62
log ,
42
63
commandRunner ) ;
43
64
await ret . CacheParents ( ) ;
@@ -61,10 +82,12 @@ public static async Task<GitRepoInspector> FromPath(string path, ILogger? log =
61
82
public string Root { get ; }
62
83
private Dictionary < Commit , Commit > CachedParents { get ; } = new ( ) ;
63
84
private ( int depth , bool shallow , Commit deepest ) ? FetchDepth { get ; set ; }
85
+ public string Remote { get ; }
64
86
65
- private GitRepoInspector ( string root , ILogger ? log , ICommandRunner commandRunner )
87
+ private GitRepoInspector ( string root , string remote , ILogger ? log , ICommandRunner commandRunner )
66
88
{
67
89
Root = root ;
90
+ Remote = remote ;
68
91
Log = log ;
69
92
CommandRunner = commandRunner ;
70
93
}
@@ -170,11 +193,9 @@ private async Task Deepen()
170
193
try
171
194
{
172
195
if ( DeepenFromCommitSupported )
173
- _ = await Git ( "fetch" , "origin" , FetchDepth . Value . deepest . Id , $ "--depth={ deltaDepth } ") ;
196
+ _ = await Git ( "fetch" , Remote , FetchDepth . Value . deepest . Id , $ "--depth={ deltaDepth } ") ;
174
197
else
175
- _ = await Git ( "fetch" , $ "--depth={ newDepth } ") ;
176
-
177
- await CacheParents ( ) ;
198
+ _ = await Git ( "fetch" , Remote , $ "--depth={ newDepth } ") ;
178
199
}
179
200
catch ( CommandException ex )
180
201
when (
@@ -275,7 +296,7 @@ public async Task<TagContainer> GetTags(QueryTarget queryTarget)
275
296
try
276
297
{
277
298
Log ? . Verbatim ( $ "GetTags(): Reading remote tags.") ;
278
- var ( response , _) = await Git ( "ls-remote" , "--tags" ) ;
299
+ var ( response , _) = await Git ( "ls-remote" , "--tags" , Remote , "*" ) ;
279
300
280
301
foreach ( Tag tag in MatchTags ( response ) )
281
302
{
@@ -318,5 +339,11 @@ public async Task FetchTag(Tag tag, string remote)
318
339
else
319
340
await Git ( "fetch" , remote , $ "refs/tags/{ tag . Name } :refs/tags/{ tag . Name } ") ;
320
341
}
342
+
343
+ /// <inheritdoc/>
344
+ public Task FetchTag ( Tag tag )
345
+ {
346
+ return FetchTag ( tag , Remote ) ;
347
+ }
321
348
}
322
349
}
0 commit comments