From 60974f11275eabfdfb364a76130aded590cb144d Mon Sep 17 00:00:00 2001 From: Matt Kotsenas Date: Mon, 15 Jul 2024 10:42:54 -0700 Subject: [PATCH 1/2] Map SourceBranchName from sourcelink to RepositoryBranch for NuGet pack --- .../NuGet.Build.Tasks.Pack.targets | 1 + .../Dotnet.Integration.Test/PackCommandTests.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets b/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets index c436123c886..b34adec5f9d 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets +++ b/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets @@ -292,6 +292,7 @@ Copyright (c) .NET Foundation. All rights reserved. $(PrivateRepositoryUrl) $(SourceRevisionId) + $(SourceBranchName) diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs index 3f70cab3b3a..aab6775457e 100644 --- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs +++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs @@ -3667,6 +3667,7 @@ public void PackCommand_PackWithSourceControlInformation_Unsupported_VerifyNuspe e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1 https://github.com/NuGet/NuGet.Client.git + refs/heads/main "); @@ -3787,6 +3788,7 @@ public void PackCommand_PackWithSourceControlInformation_PublishedUrl_VerifyNusp e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1 https://github.com/NuGet/NuGet.Client.git + refs/heads/main "; @@ -3809,7 +3811,7 @@ public void PackCommand_PackWithSourceControlInformation_PublishedUrl_VerifyNusp var repositoryMetadata = nuspecReader.GetRepositoryMetadata(); repositoryMetadata.Type.Should().Be("git"); repositoryMetadata.Url.Should().Be("https://github.com/NuGet/NuGet.Client.git"); - repositoryMetadata.Branch.Should().Be(""); + repositoryMetadata.Branch.Should().Be("refs/heads/main"); repositoryMetadata.Commit.Should().Be("e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1"); } } @@ -3836,6 +3838,7 @@ public void PackCommand_PackWithSourceControlInformation_ProjectOverride_VerifyN ProjectFileUtils.AddProperty(xml, "PublishRepositoryUrl", "true"); ProjectFileUtils.AddProperty(xml, "RepositoryCommit", "1111111111111111111111111111111111111111"); ProjectFileUtils.AddProperty(xml, "RepositoryUrl", "https://github.com/Overridden"); + ProjectFileUtils.AddProperty(xml, "RepositoryBranch", "refs/heads/overwritten"); // mock implementation of InitializeSourceControlInformation common targets: xml.Root.Add( @@ -3843,7 +3846,8 @@ public void PackCommand_PackWithSourceControlInformation_ProjectOverride_VerifyN new XAttribute("Name", "InitializeSourceControlInformation"), new XElement(ns + "PropertyGroup", new XElement("SourceRevisionId", "e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1"), - new XElement("PrivateRepositoryUrl", "https://github.com/NuGet/NuGet.Client")))); + new XElement("PrivateRepositoryUrl", "https://github.com/NuGet/NuGet.Client"), + new XElement("SourceBranchName", "refs/heads/main")))); xml.Root.Add( new XElement(ns + "PropertyGroup", @@ -3868,7 +3872,7 @@ public void PackCommand_PackWithSourceControlInformation_ProjectOverride_VerifyN var repositoryMetadata = nuspecReader.GetRepositoryMetadata(); repositoryMetadata.Type.Should().Be("git"); repositoryMetadata.Url.Should().Be("https://github.com/Overridden"); - repositoryMetadata.Branch.Should().Be(""); + repositoryMetadata.Branch.Should().Be("refs/heads/overwritten"); repositoryMetadata.Commit.Should().Be("1111111111111111111111111111111111111111"); } } From d8ed323aa97a41047f068dc7b9f30020b7c19c1b Mon Sep 17 00:00:00 2001 From: Matt Kotsenas Date: Fri, 26 Jul 2024 15:41:14 -0700 Subject: [PATCH 2/2] Only map SourceBranchName if PublishRepositoryUrl is also set --- .../NuGet.Build.Tasks.Pack.targets | 4 ++-- .../Dotnet.Integration.Test/PackCommandTests.cs | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets b/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets index b34adec5f9d..3ac25dde172 100644 --- a/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets +++ b/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets @@ -289,10 +289,10 @@ Copyright (c) .NET Foundation. All rights reserved. DependsOnTargets="InitializeSourceControlInformation" Condition="'$(SourceControlInformationFeatureSupported)' == 'true'"> - + $(PrivateRepositoryUrl) $(SourceRevisionId) - $(SourceBranchName) + $(SourceBranchName) diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs index aab6775457e..0c804e73d02 100644 --- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs +++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/PackCommandTests.cs @@ -3694,8 +3694,10 @@ public void PackCommand_PackWithSourceControlInformation_Unsupported_VerifyNuspe } } - [PlatformFact(Platform.Windows)] - public void PackCommand_PackWithSourceControlInformation_PrivateUrl_VerifyNuspec() + [PlatformTheory(Platform.Windows)] + [InlineData(true)] + [InlineData(false)] + public void PackCommand_PackWithSourceControlInformation_PrivateUrl_VerifyNuspec(bool shouldEmitPublishProperty) { using (var testDirectory = _dotnetFixture.CreateTestDirectory()) { @@ -3712,6 +3714,10 @@ public void PackCommand_PackWithSourceControlInformation_PrivateUrl_VerifyNuspec var ns = xml.Root.Name.Namespace; ProjectFileUtils.AddProperty(xml, "RepositoryType", "git"); + if (shouldEmitPublishProperty) + { + ProjectFileUtils.AddProperty(xml, "PublishRepositoryUrl", "false"); + } xml.Root.Add( new XElement(ns + "PropertyGroup", @@ -3726,6 +3732,7 @@ public void PackCommand_PackWithSourceControlInformation_PrivateUrl_VerifyNuspec e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1 https://github.com/NuGet/NuGet.Client.git + refs/heads/abc ";