@@ -25,14 +25,14 @@ internal static class GitOperations
25
25
private const string UrlSectionName = "url" ;
26
26
private const string UrlVariableName = "url" ;
27
27
28
- public static string ? GetRepositoryUrl ( GitRepository repository , string ? remoteName , Action < string , object ? [ ] > ? logWarning = null )
29
- => GetRepositoryUrl ( repository , remoteName , recursionDepth : 0 , logWarning ) ;
28
+ public static string ? GetRepositoryUrl ( GitRepository repository , string ? remoteName , bool warnOnMissingRemote = true , Action < string , object ? [ ] > ? logWarning = null )
29
+ => GetRepositoryUrl ( repository , remoteName , recursionDepth : 0 , warnOnMissingRemote , logWarning ) ;
30
30
31
- private static string ? GetRepositoryUrl ( GitRepository repository , string ? remoteName , int recursionDepth , Action < string , object ? [ ] > ? logWarning = null )
31
+ private static string ? GetRepositoryUrl ( GitRepository repository , string ? remoteName , int recursionDepth , bool warnOnMissingRemote , Action < string , object ? [ ] > ? logWarning )
32
32
{
33
33
NullableDebug . Assert ( repository . WorkingDirectory != null ) ;
34
34
35
- var remoteUrl = GetRemoteUrl ( repository , ref remoteName , logWarning ) ;
35
+ var remoteUrl = GetRemoteUrl ( repository , ref remoteName , warnOnMissingRemote , logWarning ) ;
36
36
if ( remoteUrl == null )
37
37
{
38
38
return null ;
@@ -45,10 +45,10 @@ internal static class GitOperations
45
45
return null ;
46
46
}
47
47
48
- return ResolveUrl ( uri , repository . Environment , remoteName , recursionDepth , logWarning ) ;
48
+ return ResolveUrl ( uri , repository . Environment , remoteName , recursionDepth , warnOnMissingRemote , logWarning ) ;
49
49
}
50
50
51
- private static string ? GetRemoteUrl ( GitRepository repository , ref string ? remoteName , Action < string , object ? [ ] > ? logWarning )
51
+ private static string ? GetRemoteUrl ( GitRepository repository , ref string ? remoteName , bool warnOnMissingRemote , Action < string , object ? [ ] > ? logWarning )
52
52
{
53
53
string ? unknownRemoteName = null ;
54
54
string ? remoteUrl = null ;
@@ -63,7 +63,11 @@ internal static class GitOperations
63
63
64
64
if ( remoteUrl == null && ! TryGetRemote ( repository . Config , out remoteName , out remoteUrl ) )
65
65
{
66
- logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repository . WorkingDirectory } ) ;
66
+ if ( warnOnMissingRemote )
67
+ {
68
+ logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repository . WorkingDirectory } ) ;
69
+ }
70
+
67
71
return null ;
68
72
}
69
73
@@ -75,7 +79,7 @@ internal static class GitOperations
75
79
return remoteUrl ;
76
80
}
77
81
78
- private static string ? ResolveUrl ( Uri uri , GitEnvironment environment , string ? remoteName , int recursionDepth , Action < string , object ? [ ] > ? logWarning )
82
+ private static string ? ResolveUrl ( Uri uri , GitEnvironment environment , string ? remoteName , int recursionDepth , bool warnOnMissingRemote , Action < string , object ? [ ] > ? logWarning )
79
83
{
80
84
if ( ! uri . IsFile )
81
85
{
@@ -85,7 +89,11 @@ internal static class GitOperations
85
89
var repositoryPath = uri . LocalPath ;
86
90
if ( ! GitRepository . TryGetRepositoryLocation ( repositoryPath , out var remoteRepositoryLocation ) )
87
91
{
88
- logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repositoryPath } ) ;
92
+ if ( warnOnMissingRemote )
93
+ {
94
+ logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repositoryPath } ) ;
95
+ }
96
+
89
97
return uri . AbsoluteUri ;
90
98
}
91
99
@@ -102,7 +110,7 @@ internal static class GitOperations
102
110
return null ;
103
111
}
104
112
105
- return GetRepositoryUrl ( remoteRepository , remoteName , recursionDepth + 1 , logWarning ) ?? uri . AbsoluteUri ;
113
+ return GetRepositoryUrl ( remoteRepository , remoteName , recursionDepth + 1 , warnOnMissingRemote , logWarning ) ?? uri . AbsoluteUri ;
106
114
}
107
115
108
116
private static bool TryGetRemote ( GitConfig config , [ NotNullWhen ( true ) ] out string ? remoteName , [ NotNullWhen ( true ) ] out string ? remoteUrl )
@@ -239,7 +247,7 @@ private static bool TryParseScp(string value, [NotNullWhen(true)]out Uri? uri)
239
247
return Uri . TryCreate ( url , UriKind . Absolute , out uri ) ;
240
248
}
241
249
242
- public static ITaskItem [ ] GetSourceRoots ( GitRepository repository , string ? remoteName , Action < string , object ? [ ] > logWarning )
250
+ public static ITaskItem [ ] GetSourceRoots ( GitRepository repository , string ? remoteName , bool warnOnMissingCommit , Action < string , object ? [ ] > logWarning )
243
251
{
244
252
// Not supported for repositories without a working directory.
245
253
NullableDebug . Assert ( repository . WorkingDirectory != null ) ;
@@ -262,7 +270,7 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot
262
270
item . SetMetadata ( Names . SourceRoot . RevisionId , revisionId ) ;
263
271
result . Add ( item ) ;
264
272
}
265
- else
273
+ else if ( warnOnMissingCommit )
266
274
{
267
275
logWarning ( Resources . RepositoryHasNoCommit , Array . Empty < object > ( ) ) ;
268
276
}
@@ -298,7 +306,7 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot
298
306
continue ;
299
307
}
300
308
301
- var submoduleUrl = ResolveUrl ( submoduleUri , repository . Environment , remoteName , recursionDepth : 0 , logWarning ) ;
309
+ var submoduleUrl = ResolveUrl ( submoduleUri , repository . Environment , remoteName , recursionDepth : 0 , warnOnMissingRemote : true , logWarning ) ;
302
310
if ( submoduleUrl == null )
303
311
{
304
312
logWarning ( Resources . SourceCodeWontBeAvailableViaSourceLink ,
0 commit comments