Skip to content

Stop updating git-info files when they don't exist #4866

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
merged 18 commits into from
May 23, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Microsoft.DotNet.DarcLib.Helpers;
using Microsoft.DotNet.DarcLib.Models.VirtualMonoRepo;
using Microsoft.Extensions.Logging;

#nullable enable
namespace Microsoft.DotNet.DarcLib.VirtualMonoRepo;
Expand Down Expand Up @@ -47,6 +48,7 @@ public class VmrDependencyTracker : IVmrDependencyTracker
private readonly IVmrInfo _vmrInfo;
private readonly IFileSystem _fileSystem;
private readonly ISourceMappingParser _sourceMappingParser;
private readonly ILogger<VmrDependencyTracker> _logger;
private IReadOnlyCollection<SourceMapping>? _mappings;

public IReadOnlyCollection<SourceMapping> Mappings
Expand All @@ -58,12 +60,14 @@ public VmrDependencyTracker(
IVmrInfo vmrInfo,
IFileSystem fileSystem,
ISourceMappingParser sourceMappingParser,
ISourceManifest sourceManifest)
ISourceManifest sourceManifest,
ILogger<VmrDependencyTracker> logger)
{
_vmrInfo = vmrInfo;
_sourceManifest = sourceManifest;
_fileSystem = fileSystem;
_sourceMappingParser = sourceMappingParser;
_logger = logger;
_mappings = null;
}

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

var gitInfoDirPath = _vmrInfo.VmrPath / VmrInfo.GitInfoSourcesDir;

// Only update git-info files if the git-info directory exists
if (!_fileSystem.DirectoryExists(gitInfoDirPath))
{
_logger.LogInformation("Skipped creating git-info files for {repo} as the git-info directory doesn't exist", update.Mapping.Name);
return;
}

// Root repository of an update does not have a package version associated with it
// For installer, we leave whatever was there (e.g. 8.0.100)
// For one-off non-recursive updates of repositories, we keep the previous
Expand All @@ -125,13 +138,24 @@ public void UpdateDependencyVersion(VmrDependencyUpdate update)
OutputPackageVersion = packageVersion,
};

gitInfo.SerializeToXml(GetGitInfoFilePath(update.Mapping));
var gitInfoFilePath = GetGitInfoFilePath(update.Mapping);
gitInfo.SerializeToXml(gitInfoFilePath);
_logger.LogInformation("Updated git-info file {file} for {repo}", gitInfoFilePath, update.Mapping.Name);
}

public bool RemoveRepositoryVersion(string repo)
{
var hasChanges = false;

var gitInfoDirPath = _vmrInfo.VmrPath / VmrInfo.GitInfoSourcesDir;

// Only try to delete git-info files if the git-info directory exists
if (!_fileSystem.DirectoryExists(gitInfoDirPath))
{
_logger.LogInformation("Skipped removing git-info file for {repo} as the git-info directory doesn't exist", repo);
return hasChanges;
}

var gitInfoFilePath = GetGitInfoFilePath(repo);
if (_fileSystem.FileExists(gitInfoFilePath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,15 @@ protected async Task<IReadOnlyCollection<VmrIngestionPatch>> UpdateRepoToRevisio

var filesToAdd = new List<string>
{
VmrInfo.GitInfoSourcesDir,
_vmrInfo.SourceManifestPath
};

// Only add the git-info directory to staging if it exists
var gitInfoDirPath = _vmrInfo.VmrPath / VmrInfo.GitInfoSourcesDir;
if (_fileSystem.DirectoryExists(gitInfoDirPath))
{
filesToAdd.Add(VmrInfo.GitInfoSourcesDir);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.DarcLib.Helpers;
using Microsoft.DotNet.DarcLib.Models.VirtualMonoRepo;
Expand All @@ -22,7 +23,6 @@ internal class VmrSyncAdditionalMappingsTest : VmrTestsBase
public async Task NonSrcContentIsSyncedTest()
{
// Initialize the repo

await InitializeRepoAtLastCommit(Constants.ProductRepoName, ProductRepoPath);

var expectedFilesFromRepos = new List<NativePath>
Expand All @@ -38,6 +38,9 @@ public async Task NonSrcContentIsSyncedTest()
expectedFilesFromRepos
);

// The git-info files are not created in this test so we should not expect them
expectedFiles = [..expectedFiles.Where(f => !f.Path.Contains(new NativePath(VmrInfo.GitInfoSourcesDir)))];

CheckDirectoryContents(VmrPath, expectedFiles);
await GitOperations.CheckAllIsCommitted(VmrPath);

Expand Down Expand Up @@ -69,6 +72,9 @@ protected override async Task CopyVmrForCurrentTest()
{
CopyDirectory(VmrTestsOneTimeSetUp.CommonVmrPath, VmrPath);

// In this test, we remove the git-info directory to see that it does not get created
Directory.Delete(VmrPath / "prereqs" / "git-info");

var sourceMappings = new SourceMappingFile()
{
Mappings =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public async Task Setup()

await CopyReposForCurrentTest();
await CopyVmrForCurrentTest();

// Ensure git-info directory exists for tests
Directory.CreateDirectory(VmrPath / "prereqs");
Directory.CreateDirectory(VmrPath / "prereqs" / "git-info");

ServiceProvider = CreateServiceProvider().BuildServiceProvider();
ServiceProvider.GetRequiredService<IVmrInfo>().VmrUri = VmrPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public async Task OneTimeSetUp()

Directory.CreateDirectory(TestsDirectory / Constants.VmrName);
Directory.CreateDirectory(TestsDirectory / Constants.VmrName / VmrInfo.SourcesDir);
Directory.CreateDirectory(TestsDirectory / Constants.VmrName / VmrInfo.GitInfoSourcesDir);
await _gitOperations.InitialCommit(TestsDirectory / Constants.VmrName);

await CreateRepository(CommonProductRepoPath, Constants.ProductRepoName, Constants.GetRepoFileName(Constants.ProductRepoName));
Expand Down