-
Notifications
You must be signed in to change notification settings - Fork 140
Migrate Tasks.Git.LocateRepository to multithreaded task model #1734
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
Merged
ViktorHofer
merged 10 commits into
dotnet:main
from
jankratochvilcz:mt/locate-repository
Jul 8, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
366be8a
Migrate Tasks.Git.LocateRepository to multithreaded task model
jankratochvilcz 1f29ff7
Fix inaccurate comment about AbsolutePath implicit conversion
jankratochvilcz b0b4659
Address review feedback: graceful empty-path handling
jankratochvilcz 7d3785c
Removes unneeded comment
jankratochvilcz b63e335
Reject non-fully-qualified paths instead of absolutizing (LocateRepos…
jankratochvilcz 133ee87
Shorten IsPathFullyQualified doc and reject-relative guard comments
jankratochvilcz 170fae5
Extract reusable MockEngine4 test double
jankratochvilcz fa7072a
Merge branch 'main' into mt/locate-repository
jankratochvilcz 3b2d360
Address review: extend existing MockEngine to IBuildEngine4 instead o…
jankratochvilcz 8e9e319
Simplify relative-path test: drop CWD manipulation
jankratochvilcz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the License.txt file in the project root for more information. | ||
|
|
||
| using Xunit; | ||
|
|
||
| // Some tests in this assembly temporarily change the process current working directory to validate that | ||
| // repository discovery resolves paths against the task's project directory rather than the process CWD. | ||
| // Disable test parallelization in this assembly so that the CWD mutation can't race with other tests. | ||
| [assembly: CollectionBehavior(DisableTestParallelization = true)] | ||
68 changes: 68 additions & 0 deletions
68
src/Microsoft.Build.Tasks.Git.UnitTests/LocateRepositoryTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the License.txt file in the project root for more information. | ||
|
|
||
| using TestUtilities; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Build.Tasks.Git.UnitTests | ||
| { | ||
| public class LocateRepositoryTests | ||
| { | ||
| /// <summary> | ||
| /// Verifies historical behavior is preserved: a fully-qualified <see cref="LocateRepository.Path"/> | ||
| /// pointing at a git repository is located and its outputs are populated. | ||
| /// </summary> | ||
| [Fact] | ||
| public void AbsolutePath_LocatesRepository() | ||
| { | ||
| using var temp = new TempRoot(); | ||
| var (repoDir, gitDir) = CreateMinimalRepository(temp); | ||
|
|
||
| var engine = new MockEngine(); | ||
| var task = new LocateRepository | ||
| { | ||
| BuildEngine = engine, | ||
| NoWarnOnMissingInfo = true, | ||
| Path = repoDir.Path, | ||
| }; | ||
|
|
||
| Assert.True(task.Execute(), engine.Log); | ||
| Assert.Equal(repoDir.Path, task.WorkingDirectory); | ||
| Assert.Equal(gitDir.Path, task.RepositoryId); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that a non-fully-qualified (here: relative) <see cref="LocateRepository.Path"/> is rejected. | ||
| /// | ||
| /// This is the multithreaded (MT) task model behavior: the process CWD is shared across projects, so it | ||
| /// must never influence repository discovery. The migrated task requires a fully-qualified path; a relative | ||
| /// path (<c>"."</c>) is rejected and reported as the "missing repository" warning instead of being resolved | ||
| /// against the process current working directory. | ||
| /// </summary> | ||
| [Fact] | ||
| public void RelativePath_IsRejected() | ||
| { | ||
| var engine = new MockEngine(); | ||
| var task = new LocateRepository | ||
| { | ||
| BuildEngine = engine, | ||
| Path = ".", | ||
| }; | ||
|
|
||
| // Not an error: repository discovery degrades to a warning. | ||
| Assert.True(task.Execute(), engine.Log); | ||
| Assert.Null(task.WorkingDirectory); | ||
| Assert.Contains("WARNING", engine.Log); | ||
| } | ||
|
|
||
| private static (TempDirectory repoDir, TempDirectory gitDir) CreateMinimalRepository(TempRoot temp) | ||
| { | ||
| var repoDir = temp.CreateDirectory(); | ||
| var gitDir = repoDir.CreateDirectory(".git"); | ||
| gitDir.CreateFile("HEAD").WriteAllText("ref: refs/heads/main\n"); | ||
| gitDir.CreateFile("config").WriteAllText(""); | ||
| return (repoDir, gitDir); | ||
| } | ||
| } | ||
| } |
60 changes: 60 additions & 0 deletions
60
src/Microsoft.Build.Tasks.Git.UnitTests/PathUtilitiesTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the License.txt file in the project root for more information. | ||
| using System; | ||
| using Microsoft.Build.Tasks.SourceControl; | ||
| using TestUtilities; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Build.Tasks.Git.UnitTests | ||
| { | ||
| public class PathUtilitiesTests | ||
| { | ||
| [ConditionalTheory(typeof(WindowsOnly))] | ||
| [InlineData(@"C:\")] | ||
| [InlineData(@"C:\repo")] | ||
| [InlineData(@"C:/repo")] | ||
| [InlineData(@"c:\repo")] | ||
| [InlineData(@"Z:\a\b")] | ||
| [InlineData(@"\\server\share")] | ||
| [InlineData(@"//server/share")] | ||
| [InlineData(@"\\?\C:\repo")] | ||
| public void IsPathFullyQualified_Windows_True(string path) | ||
| => Assert.True(PathUtilities.IsPathFullyQualified(path)); | ||
|
|
||
| [ConditionalTheory(typeof(WindowsOnly))] | ||
| [InlineData(@"C:foo")] // drive-relative: depends on the current directory of drive C | ||
| [InlineData(@"\foo")] // root-relative: depends on the current drive | ||
| [InlineData(@"/foo")] // root-relative (alt separator) | ||
| [InlineData(@"C:")] // drive with no path | ||
| [InlineData(@"1:\foo")] // invalid drive character | ||
| public void IsPathFullyQualified_Windows_False(string path) | ||
| => Assert.False(PathUtilities.IsPathFullyQualified(path)); | ||
|
|
||
| [ConditionalTheory(typeof(UnixOnly))] | ||
| [InlineData(@"/")] | ||
| [InlineData(@"/foo")] | ||
| [InlineData(@"/foo/bar")] | ||
| public void IsPathFullyQualified_Unix_True(string path) | ||
| => Assert.True(PathUtilities.IsPathFullyQualified(path)); | ||
|
|
||
| [ConditionalTheory(typeof(UnixOnly))] | ||
| [InlineData(@"C:\foo")] // not a special form on Unix | ||
| [InlineData(@"foo")] | ||
| public void IsPathFullyQualified_Unix_False(string path) | ||
| => Assert.False(PathUtilities.IsPathFullyQualified(path)); | ||
|
|
||
| [Theory] | ||
| [InlineData("")] | ||
| [InlineData("foo")] | ||
| [InlineData("foo/bar")] | ||
| [InlineData(".")] | ||
| [InlineData("..")] | ||
| public void IsPathFullyQualified_Relative_False(string path) | ||
| => Assert.False(PathUtilities.IsPathFullyQualified(path)); | ||
|
|
||
| [Fact] | ||
| public void IsPathFullyQualified_Null_Throws() | ||
| => Assert.Throws<ArgumentNullException>(() => PathUtilities.IsPathFullyQualified(null!)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed anymore.