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

GH-576: Fix relative submodule URL handling. #583

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 7 additions & 3 deletions src/Microsoft.Build.Tasks.Git/GitOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ internal static string ApplyInsteadOfUrlMapping(GitConfig config, string url)
internal static Uri? NormalizeUrl(GitRepository repository, string url)
{
// Git (v2.23.0) treats local relative URLs as relative to the working directory.
// This doesn't work when a relative URL is used in a config file locatede in a main .git directory
// This doesn't work when a relative URL is used in a config file located in a main .git directory
// but is resolved from a worktree that has a different working directory.
// Currently we implement the same behavior as git.

Expand Down Expand Up @@ -244,11 +244,13 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot
var result = new List<TaskItem>();
var repoRoot = repository.WorkingDirectory.EndWithSeparator();

string? repositoryUrl = null;

var revisionId = repository.GetHeadCommitSha();
if (revisionId != null)
{
// Don't report a warning since it has already been reported by GetRepositoryUrl task.
string? repositoryUrl = GetRepositoryUrl(repository, remoteName, logWarning: null);
repositoryUrl = GetRepositoryUrl(repository, remoteName, logWarning: null);

// Item metadata are stored msbuild-escaped. GetMetadata unescapes, SetMetadata stores the value as specified.
// Escape msbuild special characters so that URL escapes in the URL are preserved when the URL is read by GetMetadata.
Expand Down Expand Up @@ -276,7 +278,9 @@ public static ITaskItem[] GetSourceRoots(GitRepository repository, string? remot
}

// https://git-scm.com/docs/git-submodule
var submoduleUri = NormalizeUrl(repository, submodule.Url);
// GH-576: The plain NormalizeUrl normalizes against the working directory, but that is not what
// Git does for the submodule URLs. Those are relative to the root's remote URL.
var submoduleUri = NormalizeUrl(ApplyInsteadOfUrlMapping(repository.Config, submodule.Url), repositoryUrl ?? repository.WorkingDirectory);
if (submoduleUri == null)
{
logWarning(Resources.SourceCodeWontBeAvailableViaSourceLink,
Expand Down