@@ -25,14 +25,14 @@ internal static class GitOperations
2525 private const string UrlSectionName = "url" ;
2626 private const string UrlVariableName = "url" ;
2727
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 ) ;
3030
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 )
3232 {
3333 NullableDebug . Assert ( repository . WorkingDirectory != null ) ;
3434
35- var remoteUrl = GetRemoteUrl ( repository , ref remoteName , logWarning ) ;
35+ var remoteUrl = GetRemoteUrl ( repository , ref remoteName , warnOnMissingRemote , logWarning ) ;
3636 if ( remoteUrl == null )
3737 {
3838 return null ;
@@ -45,10 +45,10 @@ internal static class GitOperations
4545 return null ;
4646 }
4747
48- return ResolveUrl ( uri , repository . Environment , remoteName , recursionDepth , logWarning ) ;
48+ return ResolveUrl ( uri , repository . Environment , remoteName , recursionDepth , warnOnMissingRemote , logWarning ) ;
4949 }
5050
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 )
5252 {
5353 string ? unknownRemoteName = null ;
5454 string ? remoteUrl = null ;
@@ -63,7 +63,11 @@ internal static class GitOperations
6363
6464 if ( remoteUrl == null && ! TryGetRemote ( repository . Config , out remoteName , out remoteUrl ) )
6565 {
66- logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repository . WorkingDirectory } ) ;
66+ if ( warnOnMissingRemote )
67+ {
68+ logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repository . WorkingDirectory } ) ;
69+ }
70+
6771 return null ;
6872 }
6973
@@ -75,7 +79,7 @@ internal static class GitOperations
7579 return remoteUrl ;
7680 }
7781
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 )
7983 {
8084 if ( ! uri . IsFile )
8185 {
@@ -85,7 +89,11 @@ internal static class GitOperations
8589 var repositoryPath = uri . LocalPath ;
8690 if ( ! GitRepository . TryGetRepositoryLocation ( repositoryPath , out var remoteRepositoryLocation ) )
8791 {
88- logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repositoryPath } ) ;
92+ if ( warnOnMissingRemote )
93+ {
94+ logWarning ? . Invoke ( Resources . RepositoryHasNoRemote , new [ ] { repositoryPath } ) ;
95+ }
96+
8997 return uri . AbsoluteUri ;
9098 }
9199
@@ -102,7 +110,7 @@ internal static class GitOperations
102110 return null ;
103111 }
104112
105- return GetRepositoryUrl ( remoteRepository , remoteName , recursionDepth + 1 , logWarning ) ?? uri . AbsoluteUri ;
113+ return GetRepositoryUrl ( remoteRepository , remoteName , recursionDepth + 1 , warnOnMissingRemote , logWarning ) ?? uri . AbsoluteUri ;
106114 }
107115
108116 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)
239247 return Uri . TryCreate ( url , UriKind . Absolute , out uri ) ;
240248 }
241249
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 )
243251 {
244252 // Not supported for repositories without a working directory.
245253 NullableDebug . Assert ( repository . WorkingDirectory != null ) ;
@@ -262,7 +270,7 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot
262270 item . SetMetadata ( Names . SourceRoot . RevisionId , revisionId ) ;
263271 result . Add ( item ) ;
264272 }
265- else
273+ else if ( warnOnMissingCommit )
266274 {
267275 logWarning ( Resources . RepositoryHasNoCommit , Array . Empty < object > ( ) ) ;
268276 }
@@ -298,7 +306,7 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot
298306 continue ;
299307 }
300308
301- var submoduleUrl = ResolveUrl ( submoduleUri , repository . Environment , remoteName , recursionDepth : 0 , logWarning ) ;
309+ var submoduleUrl = ResolveUrl ( submoduleUri , repository . Environment , remoteName , recursionDepth : 0 , warnOnMissingRemote : true , logWarning ) ;
302310 if ( submoduleUrl == null )
303311 {
304312 logWarning ( Resources . SourceCodeWontBeAvailableViaSourceLink ,
0 commit comments