Repository navigation
Preserve .git suffix in repository names when generating SourceLink URLs - #1619
Conversation
Do not strip the `.git` suffix from repository names in GetSourceLinkUrlGitTask. Some repositories legitimately include `.git` as part of their name, and removing the suffix produces incorrect SourceLink URLs and 404 responses. This change keeps `.git` when it is part of the repository name. Additionally update the GitWeb provider to avoid appending `.git` when the suffix is already present, preventing URLs like `repo.git.git`. Add regression tests for repository names ending with `.git`.
There was a problem hiding this comment.
Pull request overview
Fixes SourceLink URL generation for cases where Azure Repos repository names legitimately end with .git, and prevents GitWeb URLs from ending up with duplicated .git suffixes.
Changes:
- Adjust
.githandling in the sharedGetSourceLinkUrlGitTaskwhen derivingrelativeUrlfrom the repository URL. - Update GitWeb SourceLink URL generation to append
.gitonly when missing. - Add/extend Azure Repos hosted URL parsing and regression tests for repo names ending in
.git.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/SourceLink.GitWeb/GetSourceLinkUrl.cs |
Avoids producing repo.git.git by appending .git only when absent. |
src/SourceLink.AzureRepos.Git.UnitTests/GetSourceLinkUrlTests.cs |
Adds regression tests covering Azure Repos URLs with repository names ending in .git. |
src/SourceLink.AzureRepos.Git.UnitTests/AzureDevOpsUrlParserHostedTests.cs |
Extends hosted URL parser test coverage for .git-suffixed repo names. |
src/Common/GitProvider/GetSourceLinkUrlGitTask.cs |
Changes shared .git normalization logic for repository paths before provider-specific URL building. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| // Only strip ".git" when it is a dedicated path segment ("/.git"). | ||
| // Do not strip ".git" from repository names (e.g. "repo.git"). | ||
| const string DotGitSegment = "/.git"; | ||
| if (relativeUrl.EndsWith(DotGitSegment, StringComparison.Ordinal)) | ||
| { | ||
| relativeUrl = relativeUrl[..^GitUrlSuffix.Length]; | ||
| relativeUrl = relativeUrl[..^DotGitSegment.Length]; | ||
| } |
There was a problem hiding this comment.
The new relativeUrl normalization changes behavior in two ways that look like regressions:
- It no longer trims a trailing ".git" from the repository path (e.g. "/a/b.git" now stays "/a/b.git"), which will break providers/tests that relied on the base task to normalize clone URLs (e.g. SourceLink.Common.UnitTests
TrimDotGitexpects "/a/b"). - It does trim a trailing "/.git" segment (e.g. "/a/.git" becomes "/a"), which is the opposite of the previous behavior and will break
TrimmingGitOnlyWhenSuffix.
Consider restoring the previous suffix-trimming behavior and introducing a provider-specific opt-out/hook (or a targeted exception for Azure DevOps URLs like those containing "/_git/") so only the AzureRepos case preserves ".git" in repo names without impacting other providers.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ty before returning it. The null-forgiving operator is used here to satisfy the nullable analysis.
The previous change modified the shared Git SourceLink task to preserve the `.git` suffix in repository names. This introduced regressions in other providers (e.g. Bitbucket and Common tests). The fix will be moved to the Azure Repos provider where the exact repository name is required by the Azure DevOps API, instead of changing the shared behavior for all providers.
…ies ending with .git Ensure that repository names ending with ".git" are not treated the same as repositories without the suffix and that the suffix is preserved in the generated SourceLink URL.
|
@dotnet-policy-service agree |
Fix build failure caused by accidentally duplicated test methods introduced while adding regression tests for repository names ending with `.git`.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
|
This fixes Source Link URL generation for Azure DevOps repositories whose actual repository name ends with The current logic trims the Since Source Link is included in the .NET SDK starting with .NET 8, this change may also be relevant for the following SDK branches. |
|
Started backporting to |
|
@Eales an error occurred while backporting to |
|
Friendly follow-up 👋 @tmat just wanted to check if you had a chance to look at this PR. No rush of course — just want to make sure it didn’t slip through the cracks. Happy to update anything if needed 🙂 |
|
Hi 👋 Adding a couple of folks for visibility 🙂 This PR fixes #1618 and adds regression tests for Azure Repos It should be low-risk and fully covered by tests. Happy to update anything if needed 🙏 |
|
|
||
| var result = task.Execute(); | ||
|
|
||
| // ERROR : The value of SourceRoot.RepositoryUrl with identity '/src/' is invalid: 'http://account.visualstudio.com/_git'"" |
| protected override string? BuildSourceLinkUrl(Uri contentUri, Uri gitUri, string relativeUrl, string revisionId, ITaskItem? hostItem) | ||
| { | ||
| if (!AzureDevOpsUrlParser.TryParseHostedHttp(gitUri.GetHost(), relativeUrl, out var projectPath, out var repositoryName)) | ||
| if (!AzureDevOpsUrlParser.TryParseHostedHttp(gitUri.GetHost(), gitUri.GetPath(), out var projectPath, out var repositoryName)) |
There was a problem hiding this comment.
It'd be useful to add a comment that unlike other git providers AzDO does not allow optional .git suffix and thus we are not using relativeUrl here.
Copilot research:
Provider behavior
┌──────────────────┬──────────────────────────┬────────────────────────────────────┐
│ Provider │ .git suffix supported? │ Required? │
├──────────────────┼──────────────────────────┼────────────────────────────────────┤
│ GitHub │ ✅ │ No (optional) │
├──────────────────┼──────────────────────────┼────────────────────────────────────┤
│ GitLab │ ✅ │ No (optional) │
├──────────────────┼──────────────────────────┼────────────────────────────────────┤
│ Bitbucket │ ✅ │ No (optional) │
├──────────────────┼──────────────────────────┼────────────────────────────────────┤
│ Gitea │ ✅ │ No (optional) │
├──────────────────┼──────────────────────────┼────────────────────────────────────┤
│ Gitee │ ✅ │ No (optional) │
├──────────────────┼──────────────────────────┼────────────────────────────────────┤
│ Azure DevOps │ ❌ │ N/A — adding .git can cause 404s │
└──────────────────┴──────────────────────────┴────────────────────────────────────┘
Why Azure DevOps is different
Azure DevOps uses a different URL routing scheme (/org/project/_git/repo) tied to its project-based API. It doesn't strip or remap the
.git suffix. This isn't a spec violation — it's a provider-specific design choice. Every other major provider happens to support it as
a convention, but none are required to.
Restore error comment – removal was unintentional.
|
I’ve addressed the feedback in this PR and pushed the requested changes. Could you please take another look? |
|
/backport to release/10.0.4xx |
|
Started backporting to |
Fixes #1618
Fix an issue where repository names ending with
.gitare incorrectlynormalized when generating SourceLink URLs for Azure Repos.
When the repository name itself ends with
.git, the shared Git task maynormalize the repository path and strip the suffix before it reaches the
Azure Repos provider. Azure DevOps REST APIs require the exact repository
name when constructing URLs such as:
https://dev.azure.com/org/project/_apis/git/repositories/{repositoryName}/items
Example:
Repository URL:
https://dev.azure.com/org/project/_git/repo.git
Generated SourceLink URL before:
.../_apis/git/repositories/repo/items?...
Expected:
.../_apis/git/repositories/repo.git/items?...
This change fixes the issue in the Azure Repos provider by resolving the
repository name directly from the original repository URI instead of relying
on the normalized relative path produced by the shared Git task.
Changes:
gitUri.GetPath()in the Azure Repos provider.git