Skip to content

Commit 9c4d990

Browse files
authored
Stop updating git-info files when they don't exist (#4866)
1 parent cc35b0b commit 9c4d990

File tree

5 files changed

+45
-4
lines changed

5 files changed

+45
-4
lines changed

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrDependencyTracker.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Threading.Tasks;
99
using Microsoft.DotNet.DarcLib.Helpers;
1010
using Microsoft.DotNet.DarcLib.Models.VirtualMonoRepo;
11+
using Microsoft.Extensions.Logging;
1112

1213
#nullable enable
1314
namespace Microsoft.DotNet.DarcLib.VirtualMonoRepo;
@@ -47,6 +48,7 @@ public class VmrDependencyTracker : IVmrDependencyTracker
4748
private readonly IVmrInfo _vmrInfo;
4849
private readonly IFileSystem _fileSystem;
4950
private readonly ISourceMappingParser _sourceMappingParser;
51+
private readonly ILogger<VmrDependencyTracker> _logger;
5052
private IReadOnlyCollection<SourceMapping>? _mappings;
5153

5254
public IReadOnlyCollection<SourceMapping> Mappings
@@ -58,12 +60,14 @@ public VmrDependencyTracker(
5860
IVmrInfo vmrInfo,
5961
IFileSystem fileSystem,
6062
ISourceMappingParser sourceMappingParser,
61-
ISourceManifest sourceManifest)
63+
ISourceManifest sourceManifest,
64+
ILogger<VmrDependencyTracker> logger)
6265
{
6366
_vmrInfo = vmrInfo;
6467
_sourceManifest = sourceManifest;
6568
_fileSystem = fileSystem;
6669
_sourceMappingParser = sourceMappingParser;
70+
_logger = logger;
6771
_mappings = null;
6872
}
6973

@@ -103,6 +107,15 @@ public void UpdateDependencyVersion(VmrDependencyUpdate update)
103107
update.BarId);
104108
_fileSystem.WriteToFile(_vmrInfo.SourceManifestPath, _sourceManifest.ToJson());
105109

110+
var gitInfoDirPath = _vmrInfo.VmrPath / VmrInfo.GitInfoSourcesDir;
111+
112+
// Only update git-info files if the git-info directory exists
113+
if (!_fileSystem.DirectoryExists(gitInfoDirPath))
114+
{
115+
_logger.LogInformation("Skipped creating git-info files for {repo} as the git-info directory doesn't exist", update.Mapping.Name);
116+
return;
117+
}
118+
106119
// Root repository of an update does not have a package version associated with it
107120
// For installer, we leave whatever was there (e.g. 8.0.100)
108121
// For one-off non-recursive updates of repositories, we keep the previous
@@ -125,13 +138,24 @@ public void UpdateDependencyVersion(VmrDependencyUpdate update)
125138
OutputPackageVersion = packageVersion,
126139
};
127140

128-
gitInfo.SerializeToXml(GetGitInfoFilePath(update.Mapping));
141+
var gitInfoFilePath = GetGitInfoFilePath(update.Mapping);
142+
gitInfo.SerializeToXml(gitInfoFilePath);
143+
_logger.LogInformation("Updated git-info file {file} for {repo}", gitInfoFilePath, update.Mapping.Name);
129144
}
130145

131146
public bool RemoveRepositoryVersion(string repo)
132147
{
133148
var hasChanges = false;
134149

150+
var gitInfoDirPath = _vmrInfo.VmrPath / VmrInfo.GitInfoSourcesDir;
151+
152+
// Only try to delete git-info files if the git-info directory exists
153+
if (!_fileSystem.DirectoryExists(gitInfoDirPath))
154+
{
155+
_logger.LogInformation("Skipped removing git-info file for {repo} as the git-info directory doesn't exist", repo);
156+
return hasChanges;
157+
}
158+
135159
var gitInfoFilePath = GetGitInfoFilePath(repo);
136160
if (_fileSystem.FileExists(gitInfoFilePath))
137161
{

src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrManagerBase.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,15 @@ protected async Task<IReadOnlyCollection<VmrIngestionPatch>> UpdateRepoToRevisio
109109

110110
var filesToAdd = new List<string>
111111
{
112-
VmrInfo.GitInfoSourcesDir,
113112
_vmrInfo.SourceManifestPath
114113
};
114+
115+
// Only add the git-info directory to staging if it exists
116+
var gitInfoDirPath = _vmrInfo.VmrPath / VmrInfo.GitInfoSourcesDir;
117+
if (_fileSystem.DirectoryExists(gitInfoDirPath))
118+
{
119+
filesToAdd.Add(VmrInfo.GitInfoSourcesDir);
120+
}
115121

116122
await _localGitClient.StageAsync(_vmrInfo.VmrPath, filesToAdd, cancellationToken);
117123

test/Microsoft.DotNet.Darc.VirtualMonoRepo.E2E.Tests/VmrSyncAdditionalMappingsTest.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Collections.Generic;
55
using System.IO;
6+
using System.Linq;
67
using System.Threading.Tasks;
78
using Microsoft.DotNet.DarcLib.Helpers;
89
using Microsoft.DotNet.DarcLib.Models.VirtualMonoRepo;
@@ -22,7 +23,6 @@ internal class VmrSyncAdditionalMappingsTest : VmrTestsBase
2223
public async Task NonSrcContentIsSyncedTest()
2324
{
2425
// Initialize the repo
25-
2626
await InitializeRepoAtLastCommit(Constants.ProductRepoName, ProductRepoPath);
2727

2828
var expectedFilesFromRepos = new List<NativePath>
@@ -38,6 +38,9 @@ public async Task NonSrcContentIsSyncedTest()
3838
expectedFilesFromRepos
3939
);
4040

41+
// The git-info files are not created in this test so we should not expect them
42+
expectedFiles = [..expectedFiles.Where(f => !f.Path.Contains(new NativePath(VmrInfo.GitInfoSourcesDir)))];
43+
4144
CheckDirectoryContents(VmrPath, expectedFiles);
4245
await GitOperations.CheckAllIsCommitted(VmrPath);
4346

@@ -69,6 +72,9 @@ protected override async Task CopyVmrForCurrentTest()
6972
{
7073
CopyDirectory(VmrTestsOneTimeSetUp.CommonVmrPath, VmrPath);
7174

75+
// In this test, we remove the git-info directory to see that it does not get created
76+
Directory.Delete(VmrPath / "prereqs" / "git-info");
77+
7278
var sourceMappings = new SourceMappingFile()
7379
{
7480
Mappings =

test/Microsoft.DotNet.Darc.VirtualMonoRepo.E2E.Tests/VmrTestsBase.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public async Task Setup()
6363

6464
await CopyReposForCurrentTest();
6565
await CopyVmrForCurrentTest();
66+
67+
// Ensure git-info directory exists for tests
68+
Directory.CreateDirectory(VmrPath / "prereqs");
69+
Directory.CreateDirectory(VmrPath / "prereqs" / "git-info");
6670

6771
ServiceProvider = CreateServiceProvider().BuildServiceProvider();
6872
ServiceProvider.GetRequiredService<IVmrInfo>().VmrUri = VmrPath;

test/Microsoft.DotNet.Darc.VirtualMonoRepo.E2E.Tests/VmrTestsOneTimeSetUp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public async Task OneTimeSetUp()
4545

4646
Directory.CreateDirectory(TestsDirectory / Constants.VmrName);
4747
Directory.CreateDirectory(TestsDirectory / Constants.VmrName / VmrInfo.SourcesDir);
48+
Directory.CreateDirectory(TestsDirectory / Constants.VmrName / VmrInfo.GitInfoSourcesDir);
4849
await _gitOperations.InitialCommit(TestsDirectory / Constants.VmrName);
4950

5051
await CreateRepository(CommonProductRepoPath, Constants.ProductRepoName, Constants.GetRepoFileName(Constants.ProductRepoName));

0 commit comments

Comments
 (0)