Skip to content

Commit cc35b0b

Browse files
authored
Fix darc vmr diff not accounting for checked-in but ignored files (dotnet#4876)
Resolves dotnet#4860
1 parent 26cbf2d commit cc35b0b

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/VmrDiffOperation.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ internal class VmrDiffOperation(
2323
IVersionDetailsParser versionDetailsParser,
2424
IVmrPatchHandler patchHandler,
2525
IRemoteFactory remoteFactory,
26+
ISourceMappingParser sourceMappingParser,
2627
ILocalGitRepoFactory localGitRepoFactory) : Operation
2728
{
2829
private const string GitDirectory = ".git";
@@ -43,8 +44,9 @@ public override async Task<int> ExecuteAsync()
4344
(NativePath tmpProductRepo, NativePath tmpVmrProductRepo, string mapping) = repo1.IsVmr ?
4445
await PrepareReposAsync(repo2, repo1, tmpPath) :
4546
await PrepareReposAsync(repo1, repo2, tmpPath);
46-
47-
await AddRemoteAndGenerateDiffAsync(tmpProductRepo, tmpVmrProductRepo, repo2.Ref, await GetDiffFilters(mapping));
47+
48+
IReadOnlyCollection<string> exclusionFilters = await GetDiffFilters(tmpVmrProductRepo / ".." / "..", repo1.IsVmr ? repo1.Ref : repo2.Ref, mapping);
49+
await AddRemoteAndGenerateDiffAsync(tmpProductRepo, tmpVmrProductRepo, repo2.Ref, exclusionFilters);
4850
}
4951
finally
5052
{
@@ -143,11 +145,15 @@ await processManager.ExecuteGit(tmpProductRepo, [
143145
return (repo1, repo2);
144146
}
145147

146-
private async Task<IReadOnlyCollection<string>> GetDiffFilters(string mapping)
148+
private async Task<IReadOnlyCollection<string>> GetDiffFilters(NativePath vmrPath, string commit, string mapping)
147149
{
148-
var remote = await remoteFactory.CreateRemoteAsync(DarcLib.Constants.DefaultVmrUri);
149-
return (await remote.GetSourceMappingsAsync(DarcLib.Constants.DefaultVmrUri, "main"))
150-
.First(m => m.Name == mapping).Exclude;
150+
var vmr = localGitRepoFactory.Create(vmrPath);
151+
var sourceMappings = await vmr.GetFileFromGitAsync(VmrInfo.DefaultRelativeSourceMappingsPath, commit)
152+
?? throw new FileNotFoundException($"Failed to find {VmrInfo.DefaultRelativeSourceMappingsPath} in {vmrPath} at {commit}");
153+
154+
return sourceMappingParser.ParseMappingsFromJson(sourceMappings)
155+
.First(m => m.Name == mapping)
156+
.Exclude;
151157
}
152158

153159
/// <summary>
@@ -304,7 +310,8 @@ await processManager.ExecuteGit(repoPath, [
304310
$"--initial-branch={branch}"
305311
]);
306312
await processManager.ExecuteGit(repoPath, [
307-
"add", "--all"
313+
// We need --force because some repos have files in them which are .gitignore-ed so if you'd copy their contents, some of the files would not be re-added
314+
"add", "--all", "--force"
308315
]);
309316
await processManager.ExecuteGit(repoPath, [
310317
"commit",

0 commit comments

Comments
 (0)