Skip to content

Replace direct file system access with System.IO.Abstractions (part 2) #4443

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 11 commits into from
Mar 7, 2025

Conversation

arturcic
Copy link
Member

@arturcic arturcic commented Mar 6, 2025

This pull request introduces the System.IO.Abstractions library to the project, which affects various parts of the codebase. The changes primarily focus on replacing direct file system access with the abstractions provided by the new library. Here are the most important changes:

Dependency Updates:

  • Added System.IO.Abstractions to the Directory.Packages.props and relevant project files (new-cli/Directory.Packages.props, new-cli/GitVersion.Core/GitVersion.Core.csproj, src/Directory.Packages.props). [1] [2] [3]

Code Refactoring:

  • Replaced direct file system access with System.IO.Abstractions

Other Changes:

  • Removed unnecessary file references and updated project files accordingly

These changes aim to improve testability and maintainability by abstracting file system dependencies, making it easier to mock and test file operations.

@Copilot Copilot AI review requested due to automatic review settings March 6, 2025 09:28
@arturcic arturcic changed the title Feature/system.io Replace direct file system access with System.IO.Abstractions Mar 6, 2025
@arturcic arturcic added this to the 6.2.x milestone Mar 6, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@arturcic arturcic requested a review from Copilot March 6, 2025 11:17
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR replaces direct file system calls with abstractions from System.IO.Abstractions to improve testability and maintainability. Key changes include dependency injection updates for file system access, refactoring of utility methods to use helper methods, and updates to test files to utilize the new abstractions.

Reviewed Changes

File Description
src/GitVersion.App/GlobbingResolver.cs Changed GetDirectoryInfoWrapper from a protected virtual method to a private static method using DirectoryInfoWrapper.
src/GitVersion.App/FileAppender.cs Updated log file operations to use IFileSystem and injected dependency for improved file handling.
src/GitVersion.BuildAgents.Tests/Agents/GitLabCiTests.cs Replaced direct File calls with IFileSystem usage for file operations.
new-cli/GitVersion.Core/CoreModule.cs Added System.IO.Abstractions using directive to support file-system abstraction.
src/GitVersion.App.Tests/Helpers/ProgramFixture.cs Updated argument splitting syntax and file handling to use IFileSystem.
src/GitVersion.App/ArgumentParser.cs Refactored path validation and configuration file checks to use PathHelper and IFileSystem methods.
src/GitVersion.BuildAgents.Tests/Agents/CodeBuildTests.cs Updated test file operations to use file system abstraction methods.
src/GitVersion.BuildAgents.Tests/Agents/JenkinsTests.cs Modified file access in tests to utilize IFileSystem instead of static File calls.
src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs Replaced File calls with IFileSystem-based file operations in tests.
src/GitVersion.App/GitVersionExecutor.cs Passed IFileSystem to logging configuration and used it for directory checks.
src/GitVersion.BuildAgents.Tests/Agents/EnvRunTests.cs Updated environment-related file operations to use IFileSystem.
src/GitVersion.BuildAgents.Tests/Agents/GitHubActionsTests.cs Updated file access and temporary file handling to use the file system abstraction.
src/GitVersion.App.Tests/ArgumentParserTests.cs Updated tests to create, read, and delete files via IFileSystem; note potential naming concerns in project file updates.
src/GitVersion.BuildAgents.Tests/Agents/BuildServerBaseTests.cs Modified inner BuildAgent class to receive IFileSystem dependency.
src/GitVersion.App/ArgumentParserExtensions.cs Replaced Path.DirectorySeparatorChar with PathHelper.DirectorySeparatorChar in switch argument logic.

Copilot reviewed 111 out of 111 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/GitVersion.App/GlobbingResolver.cs:16

  • Changing GetDirectoryInfoWrapper from a protected virtual method to a private static method prevents overriding the behavior, which may impact customization or testing. Confirm that this design decision is intentional.
private static DirectoryInfoWrapper GetDirectoryInfoWrapper(string workingDirectory) => new(new DirectoryInfo(workingDirectory));

src/GitVersion.App.Tests/ArgumentParserTests.cs:327

  • [nitpick] The test 'UpdateProjectFilesWithMultipleFilenames' asserts on 'UpdateAssemblyInfoFileName', which may not clearly indicate that project file updates are being validated. Consider using or introducing a more indicative property if this is not intentional.
arguments.UpdateAssemblyInfoFileName.ShouldContain(x => PathHelper.GetFileName(x).Equals("CommonAssemblyInfo.csproj"));

@arturcic arturcic requested a review from asbjornu March 6, 2025 11:43
@arturcic arturcic enabled auto-merge March 6, 2025 17:18
Copy link
Member

@asbjornu asbjornu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@arturcic arturcic merged commit 2d28179 into GitTools:main Mar 7, 2025
93 checks passed
Copy link
Contributor

mergify bot commented Mar 7, 2025

Thank you @arturcic for your contribution!

@arturcic arturcic deleted the feature/system.io branch March 11, 2025 05:59
@arturcic arturcic modified the milestones: 6.2.x, 6.2.0 Apr 1, 2025
@gittools-bot
Copy link

🎉 This issue has been resolved in version 6.2.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

@arturcic arturcic changed the title Replace direct file system access with System.IO.Abstractions Replace direct file system access with System.IO.Abstractions (part 2) Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants