Skip to content

Accept SHA-256 commit ids in GetSourceLinkUrl - #1774

Merged
tmat merged 1 commit into
dotnet:mainfrom
akashchamp:fix-sha256-revisionid
Oct 12, 2026
Merged

tmat merged 1 commit into
dotnet:mainfrom
akashchamp:fix-sha256-revisionid

Conversation

@akashchamp

Copy link
Copy Markdown
Contributor

Fixes #1772

GetSourceLinkUrlGitTask only accepted a 40-character RevisionId, so a repository using the sha256 object format failed with "is not a valid commit hash" in every Git provider (Gitea, GitHub, GitLab, ...), even though Microsoft.Build.Tasks.Git already reads SHA-256 repositories. The check now accepts 40 (SHA-1) or 64 (SHA-256) hex digits.

Tests: added a SHA-256 case to the common GetSourceLinkUrlTests and to the Gitea provider tests, plus 63/65-character and non-hex 64-character ids to RevisionId_Errors. The new success cases failed before the change. All *.UnitTests projects pass on net11.0 locally (Linux, so net472 not run).

I also checked it end to end. I made a repo with git init --object-format=sha256 and a codeberg.org remote, then built a library that references Microsoft.SourceLink.Gitea from locally packed packages. With the packages packed from main, the build fails with the error from the issue. With this change it succeeds and the generated sourcelink json is:

{"documents":{"/_/*":"https://codeberg.org/someone/app/raw/commit/5d63d07c6742459c2062776cf940483381dbf07b90c782efbc0cafd967c08b78/*"}}

Repositories using the sha256 object format produce a 64-character RevisionId, which the Git source link providers rejected as an invalid commit hash. Allow both 40 (SHA-1) and 64 (SHA-256) hex digits.

Fixes dotnet#1772
@akashchamp
akashchamp requested a review from tmat as a code owner October 8, 2026 05:05
@RiRiSharp

Copy link
Copy Markdown

LGTM. Don’t forget to accept the agreement

@tmat
tmat enabled auto-merge (squash) October 12, 2026 21:49
@drewnoakes

Copy link
Copy Markdown
Member

@akashchamp this PR is good to merge, but you'll have to accept the CLA.

var revisionId = SourceRoot.GetMetadata(Names.SourceRoot.RevisionId);
if (revisionId == null || revisionId.Length != 40 || !revisionId.All(IsHexDigit))
// SHA-1 (40 hex digits) or SHA-256 (64 hex digits) object name.
if (revisionId == null || revisionId.Length is not (40 or 64) || !revisionId.All(IsHexDigit))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just delete the length check entirely?

@akashchamp

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@tmat
tmat merged commit 7402f11 into dotnet:main Oct 12, 2026
9 checks passed
@tmat

tmat commented Oct 13, 2026

Copy link
Copy Markdown
Member

/backport to release/11.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0.1xx (link to workflow run)

tmat pushed a commit that referenced this pull request Oct 13, 2026
Repositories using the sha256 object format produce a 64-character RevisionId, which the Git source link providers rejected as an invalid commit hash. Allow both 40 (SHA-1) and 64 (SHA-256) hex digits.

Fixes #1772

Co-authored-by: akashchamp <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 19, 2026
tmat pushed a commit that referenced this pull request Nov 24, 2026
)

* Accept SHA-256 commit ids in GetSourceLinkUrl (#1774) (#1775)

Repositories using the sha256 object format produce a 64-character RevisionId, which the Git source link providers rejected as an invalid commit hash. Allow both 40 (SHA-1) and 64 (SHA-256) hex digits.

Fixes #1772

Co-authored-by: akashchamp <[email protected]>

* Merge pull request #1767 from dotnet/darc-release/11.0.1xx-c0d39cfa-e285-4d52-9528-869e3fab21cf

[release/11.0.1xx] Source code updates from dotnet/dotnet

* [release/11.0.1xx] Source code updates from dotnet/dotnet (#1780)

* Backflow from https://github.com/dotnet/dotnet / 6fa58a2 build 337734

Diff: https://github.com/dotnet/dotnet/compare/3ca2426deb737052b09ad000a50f0327d77d544f..6fa58a2ef810f82b3197d69763cedfb34c88b9fd

From: dotnet/dotnet@3ca2426
To: dotnet/dotnet@6fa58a2

[[ commit created by automation ]]

* Update dependencies from build 337734
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26480.113 -> 11.0.0-beta.26521.105)
System.CommandLine (Version 3.0.0-rtm.26480.113 -> 3.0.0)
System.IO.Hashing, System.Security.Cryptography.Xml, System.Text.Json (Version 11.0.0-rtm.26480.113 -> 11.0.0)
[[ commit created by automation ]]

* Use repository NuGet feeds in SDK integration tests

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 50a9547c-92ce-4f2e-8ee3-664b5a00f3c0

* Update dependencies from build 338664
Updated Dependencies:
Microsoft.DotNet.Arcade.Sdk (Version 11.0.0-beta.26521.105 -> 11.0.0-beta.26527.113)
System.CommandLine (Version 3.0.0 -> 3.0.0)
System.IO.Hashing, System.Security.Cryptography.Xml, System.Text.Json (Version 11.0.0 -> 11.0.0)
[[ commit created by automation ]]

---------

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Alexander Köplinger <[email protected]>
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 50a9547c-92ce-4f2e-8ee3-664b5a00f3c0

* Reset files to release/11.0.2xx

Reset patterns:
- eng/Version.Details.xml
- eng/Version.Details.props
- eng/common/*
- NuGet.config
- global.json

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: akashchamp <[email protected]>
Co-authored-by: dotnet-maestro[bot] <42748379+dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Alexander Köplinger <[email protected]>
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 50a9547c-92ce-4f2e-8ee3-664b5a00f3c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SHA256 commits are seen as invalid when using Microsoft.SourceLink.Gitea

5 participants