Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 10, 2025

This PR adds a --what-if option to the nbgv prepare-release command that allows users to simulate the prepare-release operation and see what versions would be set without actually making any git changes.

What it does

The --what-if flag enables users to preview the results of a prepare-release operation before committing to it:

# See what versions would be set with default settings
nbgv prepare-release --what-if

# Preview with custom version increment
nbgv prepare-release --what-if --versionIncrement Major

# Get machine-readable JSON output
nbgv prepare-release --what-if --format json

Implementation

  • New --what-if option: Added to the prepare-release command with appropriate help text
  • SimulatePrepareRelease method: New method in ReleaseManager that performs all the same validation and version calculation logic as the regular PrepareRelease method, but without making any git changes
  • Consistent validation: The what-if mode uses the exact same validation logic, so errors and warnings are identical to the regular mode
  • Output formats: Supports both human-readable text output (with "What-if:" prefixes) and machine-readable JSON output
  • Comprehensive testing: Added 12 new tests covering various scenarios including version increments, prerelease tags, error conditions, and edge cases

Example outputs

Text format:

What-if: v3.8 branch would track v3.8 stabilization and release.
What-if: main branch would track v3.9-alpha development.

JSON format:

{
  "CurrentBranch": {
    "Name": "main",
    "Commit": "abc123...",
    "Version": "3.9-alpha"
  },
  "NewBranch": {
    "Name": "v3.8",
    "Commit": "abc123...",
    "Version": "3.8"
  }
}

This enhancement provides a safe way for users to understand the impact of prepare-release operations before executing them, addressing the need for predictable version management workflows.

Fixes #1019.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

/// <returns>
/// A <see cref="ReleaseInfo"/> object containing information about the simulated release.
/// </returns>
public ReleaseInfo SimulatePrepareRelease(string projectDirectory, string releaseUnstableTag = null, Version nextVersion = null, VersionOptions.ReleaseVersionIncrement? versionIncrement = null, ReleaseManagerOutputMode outputMode = default)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot Instead of creating a whole new method that duplicates a bunch of logic and needs to be kept in sync between the two methods, please add a parameter to the existing PrepareRelease method, or have these two methods call a 3rd private helper method that has most of the logic and takes a whatIf switch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I've refactored the code to use a single PrepareRelease method with a whatIf parameter instead of duplicating logic in a separate SimulatePrepareRelease method. The implementation now uses a private PrepareReleaseCore helper method that contains all the shared logic and takes the whatIf parameter to determine whether to actually make git changes or just simulate them. This eliminates code duplication and keeps the two code paths in sync automatically. Fixed in commit 28d04ed.

@@ -339,6 +339,10 @@ private static RootCommand BuildCommandLine()
{
Description = "A custom message to use for the commit that changes the version number. May include {0} for the version number. If not specified, the default is \"Set version to '{0}'\".",
};
var whatIf = new Option<bool>("--what-if", Array.Empty<string>())
Copy link
Collaborator

Choose a reason for hiding this comment

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

@copilot Let's drop the optional Array.Empty argument for the string[] parameter, both here and elsewhere in the file where it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! I've removed all the optional Array.Empty<string>() arguments from the Option declarations throughout the Program.cs file, including the ones for metadata, versionIncrement, unformattedCommitMessage, whatIf, skipCloudBuildNumber, source, and define options. Fixed in commit 28d04ed.

@Copilot Copilot AI changed the title [WIP] Simulate the future version Add --what-if option to prepare-release command for simulating version changes Aug 10, 2025
@Copilot Copilot AI requested a review from AArnott August 10, 2025 19:31
Copilot finished work on behalf of AArnott August 10, 2025 19:31
…nd remove Array.Empty arguments

Co-authored-by: AArnott <[email protected]>
Copilot finished work on behalf of AArnott August 10, 2025 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simulate the future version
2 participants