Skip to content

Commit

Permalink
If short sha is available, use it for package metadata
Browse files Browse the repository at this point in the history
The short SHA (9-char version) is sufficiently unique for use to retrieve the upstream commit/tree.

Whenever the short sha is available, we should use that instead. An opt-out property UseShortSourceRevisionId allows turning off this behavior.

Fixes #94
  • Loading branch information
kzu committed May 10, 2021
1 parent 08d5e03 commit f01231e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/NuGetizer.Tasks/CreatePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public Manifest CreateManifest()
if (Manifest.TryGetMetadata("RepositoryCommit", out var repoCommit))
(metadata.Repository ??= new RepositoryMetadata()).Commit = repoCommit;

if (Manifest.TryGetMetadata("RepositorySha", out var repoSha))
(metadata.Repository ??= new RepositoryMetadata()).Commit = repoSha;

if (!string.IsNullOrEmpty(Manifest.GetMetadata("ProjectUrl")))
metadata.SetProjectUrl(Manifest.GetMetadata("ProjectUrl"));

Expand Down
2 changes: 2 additions & 0 deletions src/NuGetizer.Tasks/NuGetizer.PackageMetadata.targets
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<RepositoryUrl Condition="'$(RepositoryUrl)' != ''">$(RepositoryUrl)</RepositoryUrl>
<RepositoryBranch Condition="'$(RepositoryBranch)' != ''">$(RepositoryBranch)</RepositoryBranch>
<RepositoryCommit Condition="'$(RepositoryCommit)' != ''">$(RepositoryCommit)</RepositoryCommit>
<!-- This item metadata will override the RepositoryCommit in package metadata -->
<RepositorySha Condition="'$(UseShortSourceRevisionId)' != 'false' and '$(RepositorySha)' != ''">$(RepositorySha)</RepositorySha>
</PackageMetadata>
</ItemDefinitionGroup>

Expand Down

0 comments on commit f01231e

Please sign in to comment.