Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map SourceBranchName from sourcelink to RepositoryBranch for NuGet pack #5923

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,10 @@ Copyright (c) .NET Foundation. All rights reserved.
DependsOnTargets="InitializeSourceControlInformation"
Condition="'$(SourceControlInformationFeatureSupported)' == 'true'">
<PropertyGroup>
<!-- The project must specify PublishRepositoryUrl=true in order to publish the URL, in order to prevent inadvertent leak of internal URL. -->
<!-- The project must specify PublishRepositoryUrl=true in order to publish the URL or branch, in order to prevent inadvertent leak of internal data. -->
<RepositoryUrl Condition="'$(RepositoryUrl)' == '' and '$(PublishRepositoryUrl)' == 'true'">$(PrivateRepositoryUrl)</RepositoryUrl>
<RepositoryCommit Condition="'$(RepositoryCommit)' == ''">$(SourceRevisionId)</RepositoryCommit>
<RepositoryBranch Condition="'$(RepositoryBranch)' == '' and '$(PublishRepositoryUrl)' == 'true' and '$(SourceBranchName)' != ''">$(SourceBranchName)</RepositoryBranch>
</PropertyGroup>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3667,6 +3667,7 @@ public void PackCommand_PackWithSourceControlInformation_Unsupported_VerifyNuspe
<PropertyGroup>
<SourceRevisionId>e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1</SourceRevisionId>
<PrivateRepositoryUrl>https://github.com/NuGet/NuGet.Client.git</PrivateRepositoryUrl>
<SourceBranchName>refs/heads/main</SourceBranchName>
</PropertyGroup>
</Target>
</Project>");
Expand All @@ -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())
{
Expand All @@ -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",
Expand All @@ -3725,6 +3732,7 @@ public void PackCommand_PackWithSourceControlInformation_PrivateUrl_VerifyNuspec
<PropertyGroup>
<SourceRevisionId>e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1</SourceRevisionId>
<PrivateRepositoryUrl>https://github.com/NuGet/NuGet.Client.git</PrivateRepositoryUrl>
<SourceBranchName>refs/heads/abc</SourceBranchName>
</PropertyGroup>
</Target>
</Project>";
Expand Down Expand Up @@ -3787,6 +3795,7 @@ public void PackCommand_PackWithSourceControlInformation_PublishedUrl_VerifyNusp
<PropertyGroup>
<SourceRevisionId>e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1</SourceRevisionId>
<PrivateRepositoryUrl>https://github.com/NuGet/NuGet.Client.git</PrivateRepositoryUrl>
<SourceBranchName>refs/heads/main</SourceBranchName>
</PropertyGroup>
</Target>
</Project>";
Expand All @@ -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");
nkolev92 marked this conversation as resolved.
Show resolved Hide resolved
repositoryMetadata.Commit.Should().Be("e1c65e4524cd70ee6e22abe33e6cb6ec73938cb1");
}
}
Expand All @@ -3836,14 +3845,16 @@ 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(
new XElement(ns + "Target",
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",
Expand All @@ -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");
}
}
Expand Down