Skip to content

refactor: update remote branch handling in tests #4522

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 1 commit into from
Apr 25, 2025

Conversation

arturcic
Copy link
Member

This pull request introduces a new helper method, RenameRemote, to simplify renaming Git remotes in tests and refactors existing test cases to use this method. Additionally, it removes platform-specific test skips for Windows, enabling broader test coverage.

New Helper Method:

  • Added a RenameRemote extension method to LibGit2Sharp.RemoteCollection for renaming Git remotes more concisely. (src/GitVersion.Core.Tests/Extensions/GitRepositoryTestingExtensions.cs)

Refactoring Test Cases:

  • Replaced calls to Remotes.Rename with the new RenameRemote method in multiple test cases to improve code readability and reuse. (src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs, src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs, src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs, src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs) [1] [2] [3] [4]

Test Coverage Enhancements:

  • Removed platform-specific skips for Windows in several test cases, allowing these tests to run on all platforms. (src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs, src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs, src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs, src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs) [1] [2] [3] [4]

@Copilot Copilot AI review requested due to automatic review settings April 25, 2025 15:15
@arturcic arturcic added this to the 6.x milestone Apr 25, 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.

Pull Request Overview

This pull request refactors the handling of Git remotes in tests by introducing a new helper method (RenameRemote) to simplify renaming and by removing platform-specific skips for Windows.

  • Added a RenameRemote extension method to centralize Git remote renaming logic.
  • Updated multiple test cases to use the new helper, thereby increasing test coverage on Windows.
  • Removed conditional skips for Windows to allow tests to run on all platforms.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs Updated remote renaming call and removed Windows skips.
src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs Swapped direct remote renaming with the new extension method and removed Windows test skips.
src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs Replaced Renames with RenameRemote and removed Windows-specific skips.
src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs Updated remote renaming calls and removed Windows-dependent logic.
src/GitVersion.Core.Tests/Extensions/GitRepositoryTestingExtensions.cs Introduced the RenameRemote extension method for simplifying test remote renaming.

@arturcic arturcic force-pushed the fix/libgit2sharp-remote-rename branch from d6e1172 to 520d23d Compare April 25, 2025 15:23
@arturcic arturcic requested a review from Copilot April 25, 2025 15:24
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.

Pull Request Overview

This pull request refactors remote branch handling in tests by introducing the new RenameRemote extension method and updating tests to use it, while also removing Windows-specific test skips to improve coverage.

  • Introduces the RenameRemote extension in GitRepositoryTestingExtensions.cs.
  • Updates several test files to use RenameRemote instead of the older Remotes.Rename.
  • Removes platform-specific (Windows) test skips to enable broader test execution.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
VersionInBranchNameBaseVersionStrategyTests.cs Uses RenameRemote in place of Remotes.Rename and removes Windows skip.
VersionInMergedBranchNameScenarios.cs Uses RenameRemote and removes Windows-specific skip.
VersionInCurrentBranchNameScenarios.cs Uses RenameRemote and removes Windows-specific skip.
RemoteRepositoryScenarios.cs Uses RenameRemote instead of Remotes.Rename; Windows skip removed.
GitRepositoryTestingExtensions.cs Adds the new RenameRemote extension method for simplifying remote renaming.

@arturcic arturcic force-pushed the fix/libgit2sharp-remote-rename branch from 64dc437 to 35d7418 Compare April 25, 2025 15:25
@arturcic arturcic requested a review from Copilot April 25, 2025 15:26
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.

Pull Request Overview

This PR refactors remote branch handling in tests by introducing a new helper RenameRemote and updating existing tests to use it, while also removing platform-specific skips for Windows.

  • Introduces the RenameRemote extension method in GitRepositoryTestingExtensions.cs
  • Updates multiple integration and version strategy tests to use RenameRemote instead of the older Rename call
  • Removes Windows-specific test skips to allow broader test execution across platforms

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
VersionInBranchNameBaseVersionStrategyTests.cs Uses RenameRemote for renaming and removes Windows skip
VersionInMergedBranchNameScenarios.cs Replaces Rename call with RenameRemote and removes Windows skip
VersionInCurrentBranchNameScenarios.cs Updates remote renaming to use RenameRemote and removes Windows skip
RemoteRepositoryScenarios.cs Updates remote renaming to use RenameRemote and removes Windows skip
GitRepositoryTestingExtensions.cs Adds the new RenameRemote helper method to simplify remote renaming in tests

@arturcic arturcic requested a review from Copilot April 25, 2025 16:41
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.

Pull Request Overview

This PR refactors remote branch handling in tests by introducing a new helper method (RenameRemote) to simplify renaming Git remotes and eliminating Windows-specific test skips to improve cross-platform coverage.

  • Added the RenameRemote extension method in GitRepositoryTestingExtensions.cs.
  • Refactored multiple test cases to use RenameRemote instead of the older Remotes.Rename.
  • Removed Windows-only test skips.

Reviewed Changes

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

Show a summary per file
File Description
src/GitVersion.Core.Tests/Extensions/GitRepositoryTestingExtensions.cs Added the RenameRemote extension method with validation for renaming remotes.
src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs Updated test case to use RenameRemote and removed the conditional Windows test skip.
src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs Updated test case to use RenameRemote and removed the conditional Windows test skip.
src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs Updated test case to use RenameRemote and removed the conditional Windows test skip.
src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs Updated test case to use RenameRemote and removed the conditional Windows test skip.
Comments suppressed due to low confidence (2)

src/GitVersion.Core.Tests/Extensions/GitRepositoryTestingExtensions.cs:68

  • [nitpick] Consider adding XML documentation to the 'RenameRemote' method to clarify its purpose, parameters, and the exceptions it may throw.
public static void RenameRemote(this LibGit2Sharp.RemoteCollection remotes, string oldName, string newName)

src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs:100

  • [nitpick] The removal of the Windows platform skip enables broader test coverage; consider adding a comment noting that LibGit2Sharp compatibility on Windows has been verified to avoid potential issues.
public void CanTakeVersionFromNameOfRemoteReleaseBranch(string origin, string branchName, string expectedBaseVersion)

@arturcic arturcic force-pushed the fix/libgit2sharp-remote-rename branch from b358ce0 to c11cd7a Compare April 25, 2025 17:05
@arturcic arturcic requested a review from Copilot April 25, 2025 17:07
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.

Pull Request Overview

This PR refactors remote branch handling in tests by introducing a new helper method, RenameRemote, to simplify renaming Git remotes and by removing Windows-specific test skips to broaden test coverage.

  • Introduced the RenameRemote extension method in GitRepositoryTestingExtensions.cs.
  • Updated several integration and version strategy tests to use RenameRemote instead of the direct Remotes.Rename call.
  • Removed platform-specific skips for Windows from the tests.

Reviewed Changes

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

Show a summary per file
File Description
src/GitVersion.Core.Tests/VersionCalculation/Strategies/VersionInBranchNameBaseVersionStrategyTests.cs Removed Windows skips and updated rename call to use RenameRemote.
src/GitVersion.Core.Tests/IntegrationTests/VersionInMergedBranchNameScenarios.cs Updated rename call to use RenameRemote and removed Windows skip.
src/GitVersion.Core.Tests/IntegrationTests/VersionInCurrentBranchNameScenarios.cs Updated rename call to use RenameRemote and removed Windows skip.
src/GitVersion.Core.Tests/IntegrationTests/RemoteRepositoryScenarios.cs Updated rename call to use RenameRemote and removed Windows skip.
src/GitVersion.Core.Tests/Extensions/GitRepositoryTestingExtensions.cs Added the new RenameRemote extension method to simplify remote renaming.
Comments suppressed due to low confidence (1)

src/GitVersion.Core.Tests/Extensions/GitRepositoryTestingExtensions.cs:79

  • The RenameRemote helper currently adds a new remote using only the URL, which does not preserve additional remote configuration such as fetch refspecs. If any tests rely on these settings, consider enhancing the method to copy over these configurations as well.
remotes.Add(newName, remotes[oldName].Url);

@arturcic arturcic merged commit 29f871d into GitTools:main Apr 25, 2025
165 of 167 checks passed
@arturcic arturcic deleted the fix/libgit2sharp-remote-rename branch April 25, 2025 17:46
Copy link
Contributor

mergify bot commented Apr 25, 2025

Thank you @arturcic for your contribution!

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.

1 participant