Skip to content

Conversation

@adamzip
Copy link
Contributor

@adamzip adamzip commented Oct 21, 2025

Second part of #5312 (comment)

  • Add new parameters to TrackedPullRequest DTO
  • Create a darc vmr resolve command that validates PR state, locally cloned repos, and attempts to flow the next build to flow using the rebase strategy.
  • Move the implementations of backflow and forward flow to the parent operation (vmr codeflow operation) and reuse it in the vmr resolve operation

@adamzip adamzip force-pushed the darc-vmr-resolve branch 3 times, most recently from 5f859f5 to aeb22c3 Compare October 21, 2025 09:52
@adamzip adamzip marked this pull request as ready for review October 21, 2025 12:21
Copilot AI review requested due to automatic review settings October 21, 2025 12:21
Copy link
Contributor

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 implements the darc vmr resolve command to help users resolve codeflow conflicts encountered by Maestro. The command validates PR state, verifies local repository configurations, and attempts to flow the next build using the rebase strategy.

Key Changes:

  • Added HeadBranch and NextBuildsToApply fields to the TrackedPullRequest API model for conflict resolution
  • Refactored forward flow and backflow implementations from child operations into the parent CodeFlowOperation class for reuse
  • Implemented the new ResolveOperation with comprehensive validations for subscription state, local repositories, and branch alignment

Reviewed Changes

Copilot reviewed 8 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
PullRequestController.cs Adds two new fields to TrackedPullRequest DTO and refactors duplicate code into a helper method
LocalGitClient.cs Adds validation method to check for clean working directory (no conflicts or uncommitted changes)
Local.cs Adds methods to retrieve source dependency and source manifest from local repositories
ResolveCommandLineOptions.cs Defines command-line options for the new resolve command
ResolveOperation.cs Implements the resolve operation with validation logic and codeflow execution
ForwardFlowOperation.cs Removes FlowCodeAsync implementation, now uses parent class implementation
CodeFlowOperation.cs Moves FlowForwardAsync and FlowBackAsync implementations from child classes
BackflowOperation.cs Removes FlowCodeAsync implementation, now uses parent class implementation

@adamzip adamzip requested review from dkurepa and premun October 21, 2025 12:31
@adamzip adamzip changed the title darc vmr resolve Add darc vmr resolve operation Oct 21, 2025
Comment on lines 121 to 138
private async Task ValidateLocalVmr(Subscription subscription)
{
var mappingName = string.IsNullOrEmpty(subscription.TargetDirectory)
? subscription.SourceDirectory
: subscription.TargetDirectory;

var local = new Local(_options.GetRemoteTokenProvider(), _logger);

SourceManifest sourceManifest;
try
{
sourceManifest = await local.GetSourceManifestAsync(_vmrInfo.VmrPath);
}
catch (DependencyFileNotFoundException)
{
throw new DarcException("Could not find file `src/source-manifest.json` at the following" +
$"git repository: `{_vmrInfo.VmrPath}`. Please make sure it is a correct path to the VMR.");
}

if (!sourceManifest.Repositories.Any(repo => repo.Path.Equals(mappingName)))
{
throw new DarcException($"Could not find repo with name '{mappingName}' in the source-manifest.json" +
$" at the following git repository: `{_vmrInfo.VmrPath}. Please make sure it is a correct path to" +
" the VMR and that the mapping exists.");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is a bit useless. If you call RefreshMetadata on the IDependencyTracker, it will do all this and throw an exception.
You need to call that one anyway to load the source mappings.

Copy link
Member

Choose a reason for hiding this comment

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

Have a look at the CheckoutAsync in VmrCloneManager.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exception from RefreshMetaData() will likely be something like a "file not found" exception when trying to read source-manifest, right?
Instead, this validation provides a sensible message to the user that explains what the cause might be (maybe he is running the command from the wrong folder), and a suggestion for how to move next (make sure you run it from the correct target repo of the subscription)

Copy link
Member

@premun premun Oct 23, 2025

Choose a reason for hiding this comment

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

Probably, but why re-implement what it does instead of catching that exception and turning it into your own more approchable user-friendly one?

@adamzip adamzip force-pushed the darc-vmr-resolve branch 2 times, most recently from 670ddee to 96229d8 Compare October 23, 2025 11:03
Copy link
Member

@premun premun left a comment

Choose a reason for hiding this comment

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

@adamzip I fail to see where we clone the source repos - does that happen naturally inside the codeflowers?

excludedAssets: excludedAssets,
headBranch,
headBranch,
targetRepoUri ?? _vmrInfo.VmrPath,
Copy link
Member

Choose a reason for hiding this comment

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

Can you take this from my branch?

If targetRepoUri is null, we'd just put there the first remote we find in the VMR dir:

var vmr = _localGitRepoFactory.Create(_vmrInfo.VmrPath);
(await vmr.GetRemotesAsync()).First().Uri

premun
premun previously approved these changes Nov 3, 2025
Copy link
Member

@premun premun left a comment

Choose a reason for hiding this comment

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

All looks good now, just some wording nits. Please give it a test locally and we can merge

…lveConflictOperation.cs

Co-authored-by: Přemek Vysoký <[email protected]>
Copy link
Member

@premun premun left a comment

Choose a reason for hiding this comment

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

@adamzip please also change the rebase scenario tests to use the new command (and then please run them locally to make sure they go green).

Also when doing so, I think they account for the fact the codeflow commands don't return 0 when conflicts are hit so we have a try/catch there but with your command, we should not expect failures so the try/catch can go.

@premun
Copy link
Member

premun commented Nov 5, 2025

I tried that out and it went green

@adamzip adamzip merged commit 866ebe2 into dotnet:main Nov 5, 2025
8 of 9 checks passed
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.

4 participants