From 7b91f1bb062a408d41f011a5b3470a3537f8c0b4 Mon Sep 17 00:00:00 2001 From: tmat Date: Thu, 6 Apr 2023 20:55:35 -0700 Subject: [PATCH 1/5] Do not report warnings when SourceLink packages are not referenced explicitly and the repository has no URL or no commit. This allows the user to build an app in a new local repo, without having to set origin remote or commit changes first. --- src/Common/GetSourceLinkUrlGitTask.cs | 10 +- .../GitDataTests.cs | 2 +- .../GitOperationsTests.cs | 54 +++++-- .../GitOperations.cs | 34 +++-- .../LocateRepository.cs | 4 +- .../RepositoryTask.cs | 6 +- .../build/Microsoft.Build.Tasks.Git.targets | 2 +- .../GenerateSourceLinkFileTests.cs | 31 ++++ .../GenerateSourceLinkFile.cs | 6 + src/SourceLink.Common/Resources.resx | 12 ++ src/SourceLink.Common/xlf/Resources.cs.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.de.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.es.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.fr.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.it.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.ja.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.ko.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.pl.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.pt-BR.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.ru.xlf | 20 +++ src/SourceLink.Common/xlf/Resources.tr.xlf | 20 +++ .../xlf/Resources.zh-Hans.xlf | 20 +++ .../xlf/Resources.zh-Hant.xlf | 20 +++ .../AzureDevOpsServerTests.cs | 4 +- .../AzureReposTests.cs | 4 +- .../BitbucketGitTests.cs | 16 +-- .../CloudHostedProvidersTests.cs | 133 +++++++++++++++++- .../GitHubTests.cs | 43 +----- .../GitLabTests.cs | 6 +- .../GitWebTests.cs | 6 +- .../GiteaTests.cs | 6 +- .../GiteeTests.cs | 6 +- .../TargetTests.cs | 6 +- .../Utilities/GitUtilities.cs | 19 ++- 34 files changed, 564 insertions(+), 106 deletions(-) diff --git a/src/Common/GetSourceLinkUrlGitTask.cs b/src/Common/GetSourceLinkUrlGitTask.cs index 254b97c7..553bd9b6 100644 --- a/src/Common/GetSourceLinkUrlGitTask.cs +++ b/src/Common/GetSourceLinkUrlGitTask.cs @@ -85,7 +85,15 @@ private void ExecuteImpl() if (string.IsNullOrEmpty(gitUrl)) { SourceLinkUrl = NotApplicableValue; - Log.LogWarning(CommonResources.UnableToDetermineRepositoryUrl); + + // If SourceRoot has commit sha but not repository URL the source control info is available, + // but the remote for the repo has not been defined yet. We already reported missing remote in that case + // (unless suppressed). + if (string.IsNullOrEmpty(SourceRoot.GetMetadata(Names.SourceRoot.RevisionId))) + { + Log.LogWarning(CommonResources.UnableToDetermineRepositoryUrl); + } + return; } diff --git a/src/Microsoft.Build.Tasks.Git.UnitTests/GitDataTests.cs b/src/Microsoft.Build.Tasks.Git.UnitTests/GitDataTests.cs index 73f02482..6eac1920 100644 --- a/src/Microsoft.Build.Tasks.Git.UnitTests/GitDataTests.cs +++ b/src/Microsoft.Build.Tasks.Git.UnitTests/GitDataTests.cs @@ -54,7 +54,7 @@ public void MinimalGitData() Assert.Equal("1111111111111111111111111111111111111111", repository.GetHeadCommitSha()); var warnings = new List<(string, object?[])>(); - var sourceRoots = GitOperations.GetSourceRoots(repository, remoteName: null, (message, args) => warnings.Add((message, args))); + var sourceRoots = GitOperations.GetSourceRoots(repository, remoteName: null, warnOnMissingCommit: true, (message, args) => warnings.Add((message, args))); AssertEx.Equal(new[] { $@"'{repoDir.Path}{s}' SourceControl='git' RevisionId='1111111111111111111111111111111111111111' ScmRepositoryUrl='http://github.com/test-org/test-repo'", diff --git a/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs b/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs index 32a3b974..51f8d0b9 100644 --- a/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs +++ b/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs @@ -448,16 +448,53 @@ public void ApplyInsteadOfUrlMapping_Multiple() Assert.Equal("A.com", actualMappedUrl); } - [Fact] - public void GetSourceRoots_RepoWithoutCommits() + [Theory] + [CombinatorialData] + public void GetSourceRoots_RepoWithoutCommits(bool warnOnMissingCommit) { var repo = CreateRepository(); var warnings = new List<(string, object?[])>(); - var items = GitOperations.GetSourceRoots(repo, remoteName: null, (message, args) => warnings.Add((message, args))); + var items = GitOperations.GetSourceRoots(repo, remoteName: null, warnOnMissingCommit, (message, args) => warnings.Add((message, args))); Assert.Empty(items); - AssertEx.Equal(new[] { Resources.RepositoryHasNoCommit }, warnings.Select(TestUtilities.InspectDiagnostic)); + AssertEx.Equal(warnOnMissingCommit ? new[] { Resources.RepositoryHasNoCommit } : Array.Empty(), warnings.Select(TestUtilities.InspectDiagnostic)); + } + + [Fact] + public void GetSourceRoots_RepoWithCommits_WithoutUrl() + { + var repo = CreateRepository( + commitSha: "0000000000000000000000000000000000000000"); + + var warnings = new List<(string, object?[])>(); + var items = GitOperations.GetSourceRoots(repo, remoteName: null, warnOnMissingCommit: true, (message, args) => warnings.Add((message, args))); + + AssertEx.Equal(new[] + { + @"'C:\src\' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'", + }, items.Select(TestUtilities.InspectSourceRoot)); + + Assert.Empty(warnings.Select(TestUtilities.InspectDiagnostic)); + } + + [Fact] + public void GetSourceRoots_RepoWithCommits_WithUrl() + { + var repo = CreateRepository( + commitSha: "0000000000000000000000000000000000000000", + config: CreateConfig( + ("remote.origin.url", "http://github.com/abc"))); + + var warnings = new List<(string, object?[])>(); + var items = GitOperations.GetSourceRoots(repo, remoteName: null, warnOnMissingCommit: true, (message, args) => warnings.Add((message, args))); + + AssertEx.Equal(new[] + { + @"'C:\src\' SourceControl='git' RevisionId='0000000000000000000000000000000000000000' ScmRepositoryUrl='http://github.com/abc'", + }, items.Select(TestUtilities.InspectSourceRoot)); + + Assert.Empty(warnings.Select(TestUtilities.InspectDiagnostic)); } [Fact] @@ -480,7 +517,7 @@ public void GetSourceRoots_RepoWithoutCommitsWithSubmodules() CreateSubmodule("sub6", "sub/6", "", "6666666666666666666666666666666666666666"))); var warnings = new List<(string, object?[])>(); - var items = GitOperations.GetSourceRoots(repo, remoteName: null, (message, args) => warnings.Add((message, args))); + var items = GitOperations.GetSourceRoots(repo, remoteName: null, warnOnMissingCommit: false, (message, args) => warnings.Add((message, args))); // Module without a configuration entry is not initialized. // URLs listed in .submodules are ignored (they are used by git submodule initialize to generate URLs stored in config). @@ -493,9 +530,8 @@ public void GetSourceRoots_RepoWithoutCommitsWithSubmodules() AssertEx.Equal(new[] { - Resources.RepositoryHasNoCommit, string.Format(Resources.SourceCodeWontBeAvailableViaSourceLink, string.Format(Resources.InvalidSubmoduleUrl, "sub4", "https:///")) - }, warnings.Select(TestUtilities.InspectDiagnostic)); ; + }, warnings.Select(TestUtilities.InspectDiagnostic)); } [Fact] @@ -511,7 +547,7 @@ public void GetSourceRoots_RepoWithCommitsWithSubmodules() CreateSubmodule("2", "sub/2", "http://2.com", "2222222222222222222222222222222222222222"))); var warnings = new List<(string, object?[])>(); - var items = GitOperations.GetSourceRoots(repo, remoteName: null, (message, args) => warnings.Add((message, args))); + var items = GitOperations.GetSourceRoots(repo, remoteName: null, warnOnMissingCommit: false, (message, args) => warnings.Add((message, args))); AssertEx.Equal(new[] { @@ -547,7 +583,7 @@ public void GetSourceRoots_RelativeSubmodulePath() CreateSubmodule("1", "sub/1", "---", "1111111111111111111111111111111111111111", containingRepositoryWorkingDir: repoDir.Path))); var warnings = new List<(string, object?[])>(); - var items = GitOperations.GetSourceRoots(repo, remoteName: null, (message, args) => warnings.Add((message, args))); + var items = GitOperations.GetSourceRoots(repo, remoteName: null, warnOnMissingCommit: false, (message, args) => warnings.Add((message, args))); AssertEx.Equal(new[] { diff --git a/src/Microsoft.Build.Tasks.Git/GitOperations.cs b/src/Microsoft.Build.Tasks.Git/GitOperations.cs index 4cf550f4..c45cd683 100644 --- a/src/Microsoft.Build.Tasks.Git/GitOperations.cs +++ b/src/Microsoft.Build.Tasks.Git/GitOperations.cs @@ -25,14 +25,14 @@ internal static class GitOperations private const string UrlSectionName = "url"; private const string UrlVariableName = "url"; - public static string? GetRepositoryUrl(GitRepository repository, string? remoteName, Action? logWarning = null) - => GetRepositoryUrl(repository, remoteName, recursionDepth: 0, logWarning); + public static string? GetRepositoryUrl(GitRepository repository, string? remoteName, bool warnOnMissingRemote = true, Action? logWarning = null) + => GetRepositoryUrl(repository, remoteName, recursionDepth: 0, warnOnMissingRemote, logWarning); - private static string? GetRepositoryUrl(GitRepository repository, string? remoteName, int recursionDepth, Action? logWarning = null) + private static string? GetRepositoryUrl(GitRepository repository, string? remoteName, int recursionDepth, bool warnOnMissingRemote, Action? logWarning) { NullableDebug.Assert(repository.WorkingDirectory != null); - var remoteUrl = GetRemoteUrl(repository, ref remoteName, logWarning); + var remoteUrl = GetRemoteUrl(repository, ref remoteName, warnOnMissingRemote, logWarning); if (remoteUrl == null) { return null; @@ -45,10 +45,10 @@ internal static class GitOperations return null; } - return ResolveUrl(uri, repository.Environment, remoteName, recursionDepth, logWarning); + return ResolveUrl(uri, repository.Environment, remoteName, recursionDepth, warnOnMissingRemote, logWarning); } - private static string? GetRemoteUrl(GitRepository repository, ref string? remoteName, Action? logWarning) + private static string? GetRemoteUrl(GitRepository repository, ref string? remoteName, bool warnOnMissingRemote, Action? logWarning) { string? unknownRemoteName = null; string? remoteUrl = null; @@ -63,7 +63,11 @@ internal static class GitOperations if (remoteUrl == null && !TryGetRemote(repository.Config, out remoteName, out remoteUrl)) { - logWarning?.Invoke(Resources.RepositoryHasNoRemote, new[] { repository.WorkingDirectory }); + if (warnOnMissingRemote) + { + logWarning?.Invoke(Resources.RepositoryHasNoRemote, new[] { repository.WorkingDirectory }); + } + return null; } @@ -75,7 +79,7 @@ internal static class GitOperations return remoteUrl; } - private static string? ResolveUrl(Uri uri, GitEnvironment environment, string? remoteName, int recursionDepth, Action? logWarning) + private static string? ResolveUrl(Uri uri, GitEnvironment environment, string? remoteName, int recursionDepth, bool warnOnMissingRemote, Action? logWarning) { if (!uri.IsFile) { @@ -85,7 +89,11 @@ internal static class GitOperations var repositoryPath = uri.LocalPath; if (!GitRepository.TryGetRepositoryLocation(repositoryPath, out var remoteRepositoryLocation)) { - logWarning?.Invoke(Resources.RepositoryHasNoRemote, new[] { repositoryPath }); + if (warnOnMissingRemote) + { + logWarning?.Invoke(Resources.RepositoryHasNoRemote, new[] { repositoryPath }); + } + return uri.AbsoluteUri; } @@ -102,7 +110,7 @@ internal static class GitOperations return null; } - return GetRepositoryUrl(remoteRepository, remoteName, recursionDepth + 1, logWarning) ?? uri.AbsoluteUri; + return GetRepositoryUrl(remoteRepository, remoteName, recursionDepth + 1, warnOnMissingRemote, logWarning) ?? uri.AbsoluteUri; } 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) return Uri.TryCreate(url, UriKind.Absolute, out uri); } - public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remoteName, Action logWarning) + public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remoteName, bool warnOnMissingCommit, Action logWarning) { // Not supported for repositories without a working directory. NullableDebug.Assert(repository.WorkingDirectory != null); @@ -262,7 +270,7 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot item.SetMetadata(Names.SourceRoot.RevisionId, revisionId); result.Add(item); } - else + else if (warnOnMissingCommit) { logWarning(Resources.RepositoryHasNoCommit, Array.Empty()); } @@ -298,7 +306,7 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot continue; } - var submoduleUrl = ResolveUrl(submoduleUri, repository.Environment, remoteName, recursionDepth: 0, logWarning); + var submoduleUrl = ResolveUrl(submoduleUri, repository.Environment, remoteName, recursionDepth: 0, warnOnMissingRemote: true, logWarning); if (submoduleUrl == null) { logWarning(Resources.SourceCodeWontBeAvailableViaSourceLink, diff --git a/src/Microsoft.Build.Tasks.Git/LocateRepository.cs b/src/Microsoft.Build.Tasks.Git/LocateRepository.cs index a592df01..01384412 100644 --- a/src/Microsoft.Build.Tasks.Git/LocateRepository.cs +++ b/src/Microsoft.Build.Tasks.Git/LocateRepository.cs @@ -53,8 +53,8 @@ private protected override void Execute(GitRepository repository) RepositoryId = repository.GitDirectory; WorkingDirectory = repository.WorkingDirectory; - Url = GitOperations.GetRepositoryUrl(repository, RemoteName, Log.LogWarning); - Roots = GitOperations.GetSourceRoots(repository, RemoteName, Log.LogWarning); + Url = GitOperations.GetRepositoryUrl(repository, RemoteName, warnOnMissingRemote: !NoWarnOnMissingInfo, Log.LogWarning); + Roots = GitOperations.GetSourceRoots(repository, RemoteName, warnOnMissingCommit: !NoWarnOnMissingInfo, Log.LogWarning); RevisionId = repository.GetHeadCommitSha(); } } diff --git a/src/Microsoft.Build.Tasks.Git/RepositoryTask.cs b/src/Microsoft.Build.Tasks.Git/RepositoryTask.cs index 2c412844..9647abf8 100644 --- a/src/Microsoft.Build.Tasks.Git/RepositoryTask.cs +++ b/src/Microsoft.Build.Tasks.Git/RepositoryTask.cs @@ -30,9 +30,9 @@ public abstract class RepositoryTask : Task #endif /// - /// True to report a warning when the repository can't be located. + /// True to report a warning when the repository can't be located, it's missing remote or a commit. /// - public bool NoWarnOnMissingRepository { get; set; } + public bool NoWarnOnMissingInfo { get; set; } public sealed override bool Execute() { @@ -62,7 +62,7 @@ bool logAssemblyLoadingErrors() private void ReportMissingRepositoryWarning(string initialPath) { - if (!NoWarnOnMissingRepository) + if (!NoWarnOnMissingInfo) { Log.LogWarning(Resources.UnableToLocateRepository, initialPath); } diff --git a/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets b/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets index f2128f70..825f665c 100644 --- a/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets +++ b/src/Microsoft.Build.Tasks.Git/build/Microsoft.Build.Tasks.Git.targets @@ -27,7 +27,7 @@ Path="$(MSBuildProjectDirectory)" RemoteName="$(GitRepositoryRemoteName)" ConfigurationScope="$(GitRepositoryConfigurationScope)" - NoWarnOnMissingRepository="$(PkgMicrosoft_Build_Tasks_Git.Equals(''))"> + NoWarnOnMissingInfo="$(PkgMicrosoft_Build_Tasks_Git.Equals(''))"> diff --git a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs index b914a1b8..8d5f66c5 100644 --- a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs +++ b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs @@ -41,6 +41,37 @@ public void Empty(bool noWarning) Assert.Null(task.FileWrite); } + [Theory] + [CombinatorialData] + public void NoRepositoryUrl(bool noWarning) + { + var sourceLinkFilePath = Path.Combine(TempRoot.Root, Guid.NewGuid().ToString()); + + var engine = new MockEngine(); + + var task = new GenerateSourceLinkFile() + { + BuildEngine = engine, + OutputFile = sourceLinkFilePath, + SourceRoots = new[] + { + new MockItem(@"C:\src1\", KVP("MappedPath", @"C:\src1\")), + new MockItem(@"C:\src2\", KVP("MappedPath", @"C:\src2\"), KVP("RevisionId", "f3dbcdfdd5b1f75613c7692f969d8df121fc3731"), KVP("SourceControl", "git")), + new MockItem(@"C:\src3\", KVP("MappedPath", @"C:\src3\"), KVP("RevisionId", "f3dbcdfdd5b1f75613c7692f969d8df121fc3731"), KVP("SourceControl", "git"), KVP("RepositoryUrl", "")), + }, + NoWarnOnMissingSourceControlInformation = noWarning, + }; + + Assert.True(task.Execute()); + + AssertEx.AssertEqualToleratingWhitespaceDifferences( + noWarning ? "" : "WARNING : " + string.Format(Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty), + engine.Log); + + Assert.Null(task.SourceLink); + Assert.Null(task.FileWrite); + } + [Fact] public void Empty_DeleteExistingFile() { diff --git a/src/SourceLink.Common/GenerateSourceLinkFile.cs b/src/SourceLink.Common/GenerateSourceLinkFile.cs index db5d00e9..8a076161 100644 --- a/src/SourceLink.Common/GenerateSourceLinkFile.cs +++ b/src/SourceLink.Common/GenerateSourceLinkFile.cs @@ -124,6 +124,8 @@ private void WriteSourceLinkFile(string? content) { if (content == null) { + Log.LogMessage(Resources.SourceLinkEmptyDeletingExistingFile, OutputFile); + File.Delete(OutputFile); FileWrite = OutputFile; return; @@ -133,6 +135,8 @@ private void WriteSourceLinkFile(string? content) if (originalContent == content) { // Don't rewrite the file if the contents is the same, just pass it to the compiler. + Log.LogMessage(Resources.SourceLinkFileUpToDate, OutputFile); + SourceLink = OutputFile; return; } @@ -141,9 +145,11 @@ private void WriteSourceLinkFile(string? content) { // File doesn't exist and the output is empty: // Do not write the file and don't pass it to the compiler. + Log.LogMessage(Resources.SourceLinkEmptyNoExistingFile, OutputFile); return; } + Log.LogMessage(Resources.SourceLinkFileUpdated, OutputFile); File.WriteAllText(OutputFile, content); FileWrite = SourceLink = OutputFile; } diff --git a/src/SourceLink.Common/Resources.resx b/src/SourceLink.Common/Resources.resx index 9bf26dfb..805c6908 100644 --- a/src/SourceLink.Common/Resources.resx +++ b/src/SourceLink.Common/Resources.resx @@ -129,6 +129,18 @@ Source control information is not available - the generated source link is empty. + + Source Link is empty, deleting existing file: '{0}'. + + + Source Link is empty, file '{0}' does not exist. + + + Source Link file '{0}' is up-to-date. + + + Updating Source Link file '{0}'. + {0} is empty: '{1}' diff --git a/src/SourceLink.Common/xlf/Resources.cs.xlf b/src/SourceLink.Common/xlf/Resources.cs.xlf index 2eb79d33..548e7545 100644 --- a/src/SourceLink.Common/xlf/Resources.cs.xlf +++ b/src/SourceLink.Common/xlf/Resources.cs.xlf @@ -32,6 +32,26 @@ Informace o řízení zdrojů nejsou k dispozici - vygenerovaný odkaz na zdroj je prázdný. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.de.xlf b/src/SourceLink.Common/xlf/Resources.de.xlf index 23a04ed3..d397f35a 100644 --- a/src/SourceLink.Common/xlf/Resources.de.xlf +++ b/src/SourceLink.Common/xlf/Resources.de.xlf @@ -32,6 +32,26 @@ Es sind keine Informationen zur Quellcodeverwaltung verfügbar. Die generierte Quellverknüpfung ist leer. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.es.xlf b/src/SourceLink.Common/xlf/Resources.es.xlf index 53573844..eba9b0f6 100644 --- a/src/SourceLink.Common/xlf/Resources.es.xlf +++ b/src/SourceLink.Common/xlf/Resources.es.xlf @@ -32,6 +32,26 @@ La información de control del código fuente no está disponible: el vínculo de origen generado está vacío. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.fr.xlf b/src/SourceLink.Common/xlf/Resources.fr.xlf index dd9adfff..ba8d1c0e 100644 --- a/src/SourceLink.Common/xlf/Resources.fr.xlf +++ b/src/SourceLink.Common/xlf/Resources.fr.xlf @@ -32,6 +32,26 @@ Les informations de contrôle de code source ne sont pas disponibles - le lien source généré est vide. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.it.xlf b/src/SourceLink.Common/xlf/Resources.it.xlf index 3de3c1b3..b3817d7b 100644 --- a/src/SourceLink.Common/xlf/Resources.it.xlf +++ b/src/SourceLink.Common/xlf/Resources.it.xlf @@ -32,6 +32,26 @@ Le informazioni sul controllo del codice sorgente non sono disponibili. Il collegamento all'origine generato è vuoto. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.ja.xlf b/src/SourceLink.Common/xlf/Resources.ja.xlf index 1b995f3d..82ef1270 100644 --- a/src/SourceLink.Common/xlf/Resources.ja.xlf +++ b/src/SourceLink.Common/xlf/Resources.ja.xlf @@ -32,6 +32,26 @@ ソース コントロール情報は利用できません。 生成されたソース リンクが空です。 + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.ko.xlf b/src/SourceLink.Common/xlf/Resources.ko.xlf index 4f6b573b..1b402a97 100644 --- a/src/SourceLink.Common/xlf/Resources.ko.xlf +++ b/src/SourceLink.Common/xlf/Resources.ko.xlf @@ -32,6 +32,26 @@ 소스 제어 정보를 사용할 수 없습니다. 생성된 소스 링크가 비어 있습니다. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.pl.xlf b/src/SourceLink.Common/xlf/Resources.pl.xlf index 14f184ad..1fa5d092 100644 --- a/src/SourceLink.Common/xlf/Resources.pl.xlf +++ b/src/SourceLink.Common/xlf/Resources.pl.xlf @@ -32,6 +32,26 @@ Informacje o kontroli źródła są niedostępne — wygenerowany link do źródła jest pusty. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.pt-BR.xlf b/src/SourceLink.Common/xlf/Resources.pt-BR.xlf index 33d1c1fc..1e22a631 100644 --- a/src/SourceLink.Common/xlf/Resources.pt-BR.xlf +++ b/src/SourceLink.Common/xlf/Resources.pt-BR.xlf @@ -32,6 +32,26 @@ As informações de controle de origem não estão disponíveis – o source link origem gerado está vazio. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.ru.xlf b/src/SourceLink.Common/xlf/Resources.ru.xlf index f62c85b2..d7f7cdbd 100644 --- a/src/SourceLink.Common/xlf/Resources.ru.xlf +++ b/src/SourceLink.Common/xlf/Resources.ru.xlf @@ -32,6 +32,26 @@ Информация о системе управления версиями недоступна — созданная исходная ссылка является пустой. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.tr.xlf b/src/SourceLink.Common/xlf/Resources.tr.xlf index e48c4d3f..4e8253a0 100644 --- a/src/SourceLink.Common/xlf/Resources.tr.xlf +++ b/src/SourceLink.Common/xlf/Resources.tr.xlf @@ -32,6 +32,26 @@ Kaynak denetimi bilgileri kullanılamıyor. Oluşturulan kaynak bağlantısı boş. + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.zh-Hans.xlf b/src/SourceLink.Common/xlf/Resources.zh-Hans.xlf index f6b38fa2..d645925d 100644 --- a/src/SourceLink.Common/xlf/Resources.zh-Hans.xlf +++ b/src/SourceLink.Common/xlf/Resources.zh-Hans.xlf @@ -32,6 +32,26 @@ 源代码管理信息不可用 - 生成的源链接为空。 + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Common/xlf/Resources.zh-Hant.xlf b/src/SourceLink.Common/xlf/Resources.zh-Hant.xlf index 2fd26e60..d15950d4 100644 --- a/src/SourceLink.Common/xlf/Resources.zh-Hant.xlf +++ b/src/SourceLink.Common/xlf/Resources.zh-Hant.xlf @@ -32,6 +32,26 @@ 無法取得原始檔控制資訊 - 產生的來源連結是空的。 + + Source Link is empty, deleting existing file: '{0}'. + Source Link is empty, deleting existing file: '{0}'. + + + + Source Link is empty, file '{0}' does not exist. + Source Link is empty, file '{0}' does not exist. + + + + Source Link file '{0}' is up-to-date. + Source Link file '{0}' is up-to-date. + + + + Updating Source Link file '{0}'. + Updating Source Link file '{0}'. + + \ No newline at end of file diff --git a/src/SourceLink.Git.IntegrationTests/AzureDevOpsServerTests.cs b/src/SourceLink.Git.IntegrationTests/AzureDevOpsServerTests.cs index a3772897..d6cab7d2 100644 --- a/src/SourceLink.Git.IntegrationTests/AzureDevOpsServerTests.cs +++ b/src/SourceLink.Git.IntegrationTests/AzureDevOpsServerTests.cs @@ -22,7 +22,7 @@ public void FullValidation_Https() var repoUrl = "https://tfs.噸.local:8080/tfs/DefaultCollection/project/_git/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -80,7 +80,7 @@ public void FullValidation_Ssh() var repoUrl = "ssh://tfs.噸.local:22/tfs/DefaultCollection/project/_ssh/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/AzureReposTests.cs b/src/SourceLink.Git.IntegrationTests/AzureReposTests.cs index b8542707..c9327fcc 100644 --- a/src/SourceLink.Git.IntegrationTests/AzureReposTests.cs +++ b/src/SourceLink.Git.IntegrationTests/AzureReposTests.cs @@ -25,7 +25,7 @@ public void FullValidation_Https(string host) var repoUrl = $"https://test.{host}/test-org/_git/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -82,7 +82,7 @@ public void FullValidation_Ssh(string host) var repoUrl = $"ssh://test@vs-ssh.{host}:22/test-org/_ssh/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/BitbucketGitTests.cs b/src/SourceLink.Git.IntegrationTests/BitbucketGitTests.cs index 6a37e7b2..f9a81abd 100644 --- a/src/SourceLink.Git.IntegrationTests/BitbucketGitTests.cs +++ b/src/SourceLink.Git.IntegrationTests/BitbucketGitTests.cs @@ -22,7 +22,7 @@ public void FullValidation_CloudHttps() var repoUrl = "https://test-user@bitbucket.org/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -76,7 +76,7 @@ public void FullValidation_EnterpriseNewHttps() var repoUrl = "https://bitbucket.domain.com/scm/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] {ProjectFileName}, + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] {ProjectFileName}, repoUrl); var commitSha = repo.Head.Tip.Sha; @@ -133,7 +133,7 @@ public void FullValidation_EnterpriseNewHttps_UrlWithPersonalToken() var repoUrl = "https://user_name%40domain.com:Bitbucket_personaltoken@bitbucket.domain.com/scm/test-org/project1.git"; var repoName = "project1"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; @@ -192,7 +192,7 @@ public void FullValidation_EnterpriseNewHttpsWithDefaultFlags() var repoUrl = "https://bitbucket.domain.com/scm/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; @@ -251,7 +251,7 @@ public void FullValidation_EnterpriseOldHttps() var repoUrl = "https://bitbucket.domain.com/scm/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -309,7 +309,7 @@ public void FullValidation_CloudSsh() var repoUrl = "test-user@噸.com:test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -367,7 +367,7 @@ public void FullValidation_EnterpriseOldSsh() var repoUrl = "test-user@噸.com:test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -425,7 +425,7 @@ public void FullValidation_EnterpriseNewSsh() var repoUrl = "test-user@噸.com:test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs b/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs index 824ae088..8a91a9a3 100644 --- a/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs +++ b/src/SourceLink.Git.IntegrationTests/CloudHostedProvidersTests.cs @@ -4,6 +4,8 @@ using System; using System.IO; +using LibGit2Sharp; +using Microsoft.Build.Tasks.Git; using TestUtilities; using Xunit; @@ -47,7 +49,7 @@ public void NoRepository_Warnings() }, expectedWarnings: new[] { - string.Format(Build.Tasks.Git.Resources.UnableToLocateRepository, ProjectDir.Path), + string.Format(Resources.UnableToLocateRepository, ProjectDir.Path), string.Format(Common.Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty), }); @@ -85,6 +87,127 @@ public void NoRepository_NoWarnings() Assert.False(File.Exists(sourceLinkFilePath)); } + [ConditionalFact(typeof(DotNetSdkAvailable))] + public void NoCommit_NoRemote_Warnings() + { + Repository.Init(workingDirectoryPath: ProjectDir.Path, gitDirectoryPath: Path.Combine(ProjectDir.Path, ".git")); + + VerifyValues( + customProps: "", + customTargets: "", + targets: new[] + { + "Build" + }, + expressions: new[] + { + "@(SourceRoot)", + }, + expectedResults: new[] + { + NuGetPackageFolders + }, + expectedWarnings: new[] + { + // Repository has no remote. + string.Format(Resources.RepositoryHasNoRemote, ProjectDir.Path), + + // Repository doesn't have any commit. + string.Format(Resources.RepositoryHasNoCommit, ProjectDir.Path), + + // No SourceRoot items specified - the generated source link is empty. + string.Format(Common.Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty), + }); + } + + [ConditionalFact(typeof(DotNetSdkAvailable))] + public void NoCommit_NoRemote_NoWarnings() + { + Repository.Init(workingDirectoryPath: ProjectDir.Path, gitDirectoryPath: Path.Combine(ProjectDir.Path, ".git")); + + VerifyValues( + customProps: """ + + + + + """, + customTargets: "", + targets: new[] + { + "Build" + }, + expressions: new[] + { + "@(SourceRoot)", + "$(SourceLink)", + }, + expectedResults: new[] + { + NuGetPackageFolders, + "", + }); + } + + [ConditionalFact(typeof(DotNetSdkAvailable))] + public void Commit_NoRemote_NoWarnings() + { + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, originUrl: null); + + VerifyValues( + customProps: """ + + + + + """, + customTargets: "", + targets: new[] + { + "Build" + }, + expressions: new[] + { + "@(SourceRoot)", + "$(SourceLink)", + }, + expectedResults: new[] + { + NuGetPackageFolders, + ProjectSourceRoot, + "", + }); + } + + [ConditionalFact(typeof(DotNetSdkAvailable))] + public void NoCommit_Remote_NoWarnings() + { + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, commitFileNames: null, originUrl: "https://github.com/org/repo"); + + VerifyValues( + customProps: """ + + + + + """, + customTargets: "", + targets: new[] + { + "Build" + }, + expressions: new[] + { + "@(SourceRoot)", + "$(SourceLink)", + }, + expectedResults: new[] + { + NuGetPackageFolders, + "", + }); + } + [ConditionalFact(typeof(DotNetSdkAvailable))] public void CustomTranslation() { @@ -93,7 +216,7 @@ public void CustomTranslation() var repoUrl = "ssh://test@vs-ssh.visualstudio.com:22/test-org/_ssh/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -170,7 +293,7 @@ public void Host_VisualStudio(string host) var repoUrl = $"https://test.{host}/test-org/_git/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -212,7 +335,7 @@ public void Host_DevAzureCom(string host) var repoUrl = $"https://{host}/test/test-org/_git/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -251,7 +374,7 @@ public void Host_Unknown() { var repoUrl = $"https://contoso.com/test/test-org/_git/test-repo"; - GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); VerifyValues( customProps: "", diff --git a/src/SourceLink.Git.IntegrationTests/GitHubTests.cs b/src/SourceLink.Git.IntegrationTests/GitHubTests.cs index 9f88ce41..623714b0 100644 --- a/src/SourceLink.Git.IntegrationTests/GitHubTests.cs +++ b/src/SourceLink.Git.IntegrationTests/GitHubTests.cs @@ -16,39 +16,6 @@ public GitHubTests() { } - [ConditionalFact(typeof(DotNetSdkAvailable))] - public void EmptyRepository() - { - Repository.Init(workingDirectoryPath: ProjectDir.Path, gitDirectoryPath: Path.Combine(ProjectDir.Path, ".git")); - - VerifyValues( - customProps: "", - customTargets: "", - targets: new[] - { - "Build" - }, - expressions: new[] - { - "@(SourceRoot)", - }, - expectedResults: new[] - { - NuGetPackageFolders - }, - expectedWarnings: new[] - { - // Repository has no remote. - string.Format(Resources.RepositoryHasNoRemote, ProjectDir.Path), - - // Repository doesn't have any commit. - string.Format(Resources.RepositoryHasNoCommit, ProjectDir.Path), - - // No SourceRoot items specified - the generated source link is empty. - string.Format(Common.Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty), - }); - } - [ConditionalFact(typeof(DotNetSdkAvailable))] public void MutlipleProjects() { @@ -63,7 +30,7 @@ public void MutlipleProjects() "); - using var repo = GitUtilities.CreateGitRepositoryWithSingleCommit( + using var repo = GitUtilities.CreateGitRepository( RootDir.Path, new[] { Path.Combine(ProjectName, ProjectFileName), Path.Combine(projectName2, projectFileName2) }, "http://github.com/test-org/test-repo1"); @@ -140,7 +107,7 @@ private void PrepareTestEnvironment() [ConditionalFact(typeof(DotNetSdkAvailable))] public void Environment_Enabled() { - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo1"); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo1"); var commitSha = repo.Head.Tip.Sha; PrepareTestEnvironment(); @@ -172,7 +139,7 @@ public void Environment_Enabled() [ConditionalFact(typeof(DotNetSdkAvailable))] public void Environment_Disabled() { - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo1"); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo1"); var commitSha = repo.Head.Tip.Sha; PrepareTestEnvironment(); @@ -213,7 +180,7 @@ public void FullValidation_Https() var repoUrl = "http://github.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -269,7 +236,7 @@ public void FullValidation_Ssh() var repoUrl = "ssh://github.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/GitLabTests.cs b/src/SourceLink.Git.IntegrationTests/GitLabTests.cs index ca4d7d99..dfc0fbc5 100644 --- a/src/SourceLink.Git.IntegrationTests/GitLabTests.cs +++ b/src/SourceLink.Git.IntegrationTests/GitLabTests.cs @@ -22,7 +22,7 @@ public void FullValidation_Https() var repoUrl = "https://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -80,7 +80,7 @@ public void FullValidation_Ssh() var repoUrl = "test-user@噸.com:test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -139,7 +139,7 @@ public void ImplicitHost() var repoUrl = "http://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/GitWebTests.cs b/src/SourceLink.Git.IntegrationTests/GitWebTests.cs index 5d37d787..3f9a54e2 100644 --- a/src/SourceLink.Git.IntegrationTests/GitWebTests.cs +++ b/src/SourceLink.Git.IntegrationTests/GitWebTests.cs @@ -24,7 +24,7 @@ public void FullValidation_Ssh() var repoUrl = $"ssh://git@噸.com/test-%72epo\u1234%24%2572%2F.git"; var repoName = "test-repo\u1234%24%2572%2F.git"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -78,7 +78,7 @@ public void FullValidation_Ssh() public void Issues_error_on_git_url() { var repoUrl = "git://噸.com/invalid_url_protocol.git"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -105,7 +105,7 @@ public void Issues_error_on_git_url() public void Issues_error_on_https_url() { var repoUrl = "https://噸.com/invalid_url_protocol.git"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/GiteaTests.cs b/src/SourceLink.Git.IntegrationTests/GiteaTests.cs index 7839062b..9d5e0e49 100644 --- a/src/SourceLink.Git.IntegrationTests/GiteaTests.cs +++ b/src/SourceLink.Git.IntegrationTests/GiteaTests.cs @@ -22,7 +22,7 @@ public void FullValidation_Https() var repoUrl = "https://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -80,7 +80,7 @@ public void FullValidation_Ssh() var repoUrl = "test-user@噸.com:test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -139,7 +139,7 @@ public void ImplicitHost() var repoUrl = "http://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/GiteeTests.cs b/src/SourceLink.Git.IntegrationTests/GiteeTests.cs index c0adbd20..044d9ccf 100644 --- a/src/SourceLink.Git.IntegrationTests/GiteeTests.cs +++ b/src/SourceLink.Git.IntegrationTests/GiteeTests.cs @@ -22,7 +22,7 @@ public void FullValidation_Https() var repoUrl = "https://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -80,7 +80,7 @@ public void FullValidation_Ssh() var repoUrl = "test-user@噸.com:test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( @@ -139,7 +139,7 @@ public void ImplicitHost() var repoUrl = "http://噸.com/test-org/test-%72epo\u1234%24%2572%2F"; var repoName = "test-repo\u1234%24%2572%2F"; - var repo = GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); + var repo = GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, repoUrl); var commitSha = repo.Head.Tip.Sha; VerifyValues( diff --git a/src/SourceLink.Git.IntegrationTests/TargetTests.cs b/src/SourceLink.Git.IntegrationTests/TargetTests.cs index 8b452a39..be09a9be 100644 --- a/src/SourceLink.Git.IntegrationTests/TargetTests.cs +++ b/src/SourceLink.Git.IntegrationTests/TargetTests.cs @@ -24,7 +24,7 @@ public TargetTests() [ConditionalFact(typeof(DotNetSdkAvailable))] public void GenerateSourceLinkFileTarget_EnableSourceLinkCondition() { - GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo"); + GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo"); VerifyValues( customProps: @" @@ -65,7 +65,7 @@ public void GenerateSourceLinkFileTarget_EnableSourceLinkCondition() [ConditionalFact(typeof(DotNetSdkAvailable))] public void DefaultValuesForEnableProperties_DesignTimeBuild() { - GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo"); + GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo"); VerifyValues( customProps: @" @@ -100,7 +100,7 @@ public void DefaultValuesForEnableProperties_DesignTimeBuild() [ConditionalFact(typeof(DotNetSdkAvailable))] public void DefaultValuesForEnableProperties_BuildingForLiveUnitTesting() { - GitUtilities.CreateGitRepositoryWithSingleCommit(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo"); + GitUtilities.CreateGitRepository(ProjectDir.Path, new[] { ProjectFileName }, "http://github.com/test-org/test-repo"); VerifyValues( customProps: @" diff --git a/src/SourceLink.Git.IntegrationTests/Utilities/GitUtilities.cs b/src/SourceLink.Git.IntegrationTests/Utilities/GitUtilities.cs index 021cdc37..3bd518f8 100644 --- a/src/SourceLink.Git.IntegrationTests/Utilities/GitUtilities.cs +++ b/src/SourceLink.Git.IntegrationTests/Utilities/GitUtilities.cs @@ -12,18 +12,25 @@ public class GitUtilities { private static readonly Signature s_signature = new Signature("test", "test@test.com", DateTimeOffset.Now); - public static Repository CreateGitRepositoryWithSingleCommit(string directory, string[] commitFileNames, string originUrl) + public static Repository CreateGitRepository(string directory, string[]? commitFileNames, string? originUrl) { var repository = new Repository(Repository.Init(workingDirectoryPath: directory, gitDirectoryPath: Path.Combine(directory, ".git"))); - repository.Network.Remotes.Add("origin", originUrl); - foreach (var fileName in commitFileNames) + if (originUrl != null) { - repository.Index.Add(fileName); + repository.Network.Remotes.Add("origin", originUrl); } - repository.Index.Write(); - repository.Commit("First commit", s_signature, s_signature); + if (commitFileNames != null) + { + foreach (var fileName in commitFileNames) + { + repository.Index.Add(fileName); + } + + repository.Index.Write(); + repository.Commit("First commit", s_signature, s_signature); + } return repository; } From f1f7383705075d006196185836c9d3e86b4f596f Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 7 Apr 2023 09:05:33 -0700 Subject: [PATCH 2/5] Update tests --- .../GenerateSourceLinkFileTests.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs index 8d5f66c5..88f95827 100644 --- a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs +++ b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs @@ -33,9 +33,11 @@ public void Empty(bool noWarning) Assert.True(task.Execute()); - AssertEx.AssertEqualToleratingWhitespaceDifferences( - noWarning ? "" : "WARNING : " + string.Format(Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty), - engine.Log); + var expectedOutput = + (noWarning ? "" : "WARNING : " + string.Format(Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty) + Environment.NewLine) + + string.Format(Resources.SourceLinkEmptyNoExistingFile, sourceLinkFilePath); + + AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedOutput, engine.Log); Assert.Null(task.SourceLink); Assert.Null(task.FileWrite); @@ -64,9 +66,11 @@ public void NoRepositoryUrl(bool noWarning) Assert.True(task.Execute()); - AssertEx.AssertEqualToleratingWhitespaceDifferences( - noWarning ? "" : "WARNING : " + string.Format(Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty), - engine.Log); + var expectedOutput = + (noWarning ? "" : "WARNING : " + string.Format(Resources.SourceControlInformationIsNotAvailableGeneratedSourceLinkEmpty) + Environment.NewLine) + + string.Format(Resources.SourceLinkEmptyNoExistingFile, sourceLinkFilePath); + + AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedOutput, engine.Log); Assert.Null(task.SourceLink); Assert.Null(task.FileWrite); @@ -92,7 +96,8 @@ public void Empty_DeleteExistingFile() Assert.True(task.Execute()); - AssertEx.AssertEqualToleratingWhitespaceDifferences("", engine.Log); + AssertEx.AssertEqualToleratingWhitespaceDifferences( + string.Format(Resources.SourceLinkEmptyDeletingExistingFile, sourceLinkFile.Path), engine.Log); Assert.Null(task.SourceLink); Assert.Equal(sourceLinkFile.Path, task.FileWrite); From cae322e6ad7b54b1e6b5a3cfdbafe995779ab8f5 Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 7 Apr 2023 09:56:14 -0700 Subject: [PATCH 3/5] Fix --- src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs b/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs index 51f8d0b9..23eee87b 100644 --- a/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs +++ b/src/Microsoft.Build.Tasks.Git.UnitTests/GitOperationsTests.cs @@ -472,7 +472,7 @@ public void GetSourceRoots_RepoWithCommits_WithoutUrl() AssertEx.Equal(new[] { - @"'C:\src\' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'", + $@"'{_workingDir}{s}' SourceControl='git' RevisionId='0000000000000000000000000000000000000000'", }, items.Select(TestUtilities.InspectSourceRoot)); Assert.Empty(warnings.Select(TestUtilities.InspectDiagnostic)); @@ -491,7 +491,7 @@ public void GetSourceRoots_RepoWithCommits_WithUrl() AssertEx.Equal(new[] { - @"'C:\src\' SourceControl='git' RevisionId='0000000000000000000000000000000000000000' ScmRepositoryUrl='http://github.com/abc'", + $@"'{_workingDir}{s}' SourceControl='git' RevisionId='0000000000000000000000000000000000000000' ScmRepositoryUrl='http://github.com/abc'", }, items.Select(TestUtilities.InspectSourceRoot)); Assert.Empty(warnings.Select(TestUtilities.InspectDiagnostic)); From 6f9e7f70a6fab8a1ea98cf35e4b7aa7e300b1eb6 Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 7 Apr 2023 09:57:11 -0700 Subject: [PATCH 4/5] Ignore .vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 652d3beb..2a0a37ea 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ *.suo *.user .vs/ +.vscode/ # Build results artifacts/ From 2544d806500c8975759c2f3d3c3797a98eeea69f Mon Sep 17 00:00:00 2001 From: tmat Date: Fri, 7 Apr 2023 10:08:37 -0700 Subject: [PATCH 5/5] Fix --- .../GenerateSourceLinkFileTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs index 88f95827..50ecb7c9 100644 --- a/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs +++ b/src/SourceLink.Common.UnitTests/GenerateSourceLinkFileTests.cs @@ -57,9 +57,9 @@ public void NoRepositoryUrl(bool noWarning) OutputFile = sourceLinkFilePath, SourceRoots = new[] { - new MockItem(@"C:\src1\", KVP("MappedPath", @"C:\src1\")), - new MockItem(@"C:\src2\", KVP("MappedPath", @"C:\src2\"), KVP("RevisionId", "f3dbcdfdd5b1f75613c7692f969d8df121fc3731"), KVP("SourceControl", "git")), - new MockItem(@"C:\src3\", KVP("MappedPath", @"C:\src3\"), KVP("RevisionId", "f3dbcdfdd5b1f75613c7692f969d8df121fc3731"), KVP("SourceControl", "git"), KVP("RepositoryUrl", "")), + new MockItem("/1/", KVP("MappedPath", "/1/")), + new MockItem("/2/", KVP("MappedPath", "/2/"), KVP("RevisionId", "f3dbcdfdd5b1f75613c7692f969d8df121fc3731"), KVP("SourceControl", "git")), + new MockItem("/3/", KVP("MappedPath", "/3/"), KVP("RevisionId", "f3dbcdfdd5b1f75613c7692f969d8df121fc3731"), KVP("SourceControl", "git"), KVP("RepositoryUrl", "")), }, NoWarnOnMissingSourceControlInformation = noWarning, };