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..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,9 +289,10 @@ Copyright (c) .NET Foundation. All rights reserved. DependsOnTargets="InitializeSourceControlInformation" Condition="'$(SourceControlInformationFeatureSupported)' == 'true'"> - + $(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..0c804e73d02 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 "); @@ -3693,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()) { @@ -3711,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", @@ -3725,6 +3732,7 @@ public void PackCommand_PackWithSourceControlInformation_PrivateUrl_VerifyNuspec e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1 https://github.com/NuGet/NuGet.Client.git + refs/heads/abc "; @@ -3787,6 +3795,7 @@ public void PackCommand_PackWithSourceControlInformation_PublishedUrl_VerifyNusp e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1 https://github.com/NuGet/NuGet.Client.git + refs/heads/main "; @@ -3809,7 +3818,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 +3845,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 +3853,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 +3879,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"); } }