Skip to content

Preserve .git suffix in repository names when generating SourceLink URLs - #1619

Merged
tmat merged 12 commits into
dotnet:mainfrom
Eales:fix
Apr 27, 2026
Merged

tmat merged 12 commits into
dotnet:mainfrom
Eales:fix

Conversation

@Eales

@Eales Eales commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1618

Fix an issue where repository names ending with .git are incorrectly
normalized when generating SourceLink URLs for Azure Repos.

When the repository name itself ends with .git, the shared Git task may
normalize 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:

  • resolve repository name from gitUri.GetPath() in the Azure Repos provider
  • keep existing behavior of the shared Git SourceLink task unchanged
  • add regression tests for repositories whose names end with .git

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`.
@Eales
Eales requested a review from tmat as a code owner March 6, 2026 00:38
Copilot AI review requested due to automatic review settings March 6, 2026 00:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 .git handling in the shared GetSourceLinkUrlGitTask when deriving relativeUrl from the repository URL.
  • Update GitWeb SourceLink URL generation to append .git only 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.

Comment on lines 136 to 142
// 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];
}

Copilot AI Mar 6, 2026

Copy link

Choose a reason for hiding this comment

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

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 TrimDotGit expects "/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.

Copilot uses AI. Check for mistakes.
Eales and others added 5 commits March 6, 2026 01:52
…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.
@Eales
Eales marked this pull request as draft March 6, 2026 01:47
@Eales
Eales marked this pull request as ready for review March 6, 2026 01:55
@Eales
Eales marked this pull request as draft March 6, 2026 06:58
Eales added 2 commits March 6, 2026 08:09
…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.
@Eales

Eales commented Mar 6, 2026

Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

Fix build failure caused by accidentally duplicated test methods
introduced while adding regression tests for repository names
ending with `.git`.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@Eales
Eales marked this pull request as ready for review March 6, 2026 08:24
@Eales

Eales commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor Author

This fixes Source Link URL generation for Azure DevOps repositories whose actual repository name ends with .git.

The current logic trims the .git suffix too early, which produces incorrect URLs such as:
.../_apis/git/repositories/soneta/items
instead of:
.../_apis/git/repositories/soneta.git/items.

Since Source Link is included in the .NET SDK starting with .NET 8, this change may also be relevant for the following SDK branches.

@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

Started backporting to release/8.0.0 (link to workflow run)

@github-actions

github-actions Bot commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

@Eales an error occurred while backporting to release/8.0.0. See the workflow output for details.

@Eales

Eales commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping 👋

@tmat could you please take a look when you have a moment?
This fixes #1618 and includes regression tests for Azure Repos repository names ending with .git.

Happy to adjust anything if needed.

@Eales

Eales commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

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 🙂

@Eales

Eales commented Apr 20, 2026

Copy link
Copy Markdown
Contributor Author

Hi 👋

Adding a couple of folks for visibility 🙂

@tmat @EgorBo @jkoritzinsky

This PR fixes #1618 and adds regression tests for Azure Repos .git edge case.

It should be low-risk and fully covered by tests.
Would appreciate a quick review or guidance on whether this is good to merge.

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'""

@tmat tmat Apr 21, 2026 •

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.

Why removing these comments?

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))

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.

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.

@Eales

Eales commented Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

I’ve addressed the feedback in this PR and pushed the requested changes.

Could you please take another look?

@tmat

@tmat

tmat commented Apr 24, 2026

Copy link
Copy Markdown
Member

/backport to release/10.0.4xx

@github-actions

Copy link
Copy Markdown
Contributor

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

@tmat
tmat merged commit 29e6c94 into dotnet:main Apr 27, 2026
9 checks passed
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.

Azure Repos: repository names ending with .git are stripped when generating SourceLink URLs

3 participants