Skip to content

Fix darc vmr cherry-pick to honor --vmr and improve error messaging#6018

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-cherry-pick-error-handling
Draft

Fix darc vmr cherry-pick to honor --vmr and improve error messaging#6018
Copilot wants to merge 2 commits intomainfrom
copilot/fix-cherry-pick-error-handling

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

darc vmr cherry-pick was silently ignoring the --vmr option and always applying patches to the current directory's git root, making it impossible to cherry-pick without being physically inside the VMR directory.

Root cause

CherryPickOperation used Environment.CurrentDirectory exclusively for VMR detection and patch application, never consulting _options.VmrPath. This caused two bugs:

  • --vmr /path/to/vmr was a no-op in the operation logic
  • Patches were always applied to the current dir, so running from a repo dir would apply changes to the repo instead of the VMR

Changes

  • VMR detection: Check _options.VmrPath (from --vmr, defaults to current dir) for source-manifest.json first. Fall back to checking --source as the VMR for backward compatibility (old pattern: run from repo, --source = VMR path).
  • Patch application: Apply patches to vmrPath when flowing repo→VMR, or repoPath when flowing VMR→repo — instead of always targeting the current dir's git root.
  • Error message: When neither path resolves to a VMR, emit a clear, actionable error:
    Could not find a VMR at 'C:\r\runtime' (missing 'C:\r\runtime\src\source-manifest.json').
    Run the operation from the VMR directory or specify the VMR path with --vmr.
    
  • Logging: Replace the ambiguous "starting from VMR/repository" message with directional arrows showing both paths:
    Cherry-picking abc123 from repository (C:\r\runtime) -> VMR (C:\r\dotnet)
    
  • Error handling: Wrap FindGitRoot calls in try/catch with actionable messages instead of letting exceptions bubble up cryptically.
Original prompt

This section details on the original issue you should resolve

<issue_title>darc vmr cherry-pick does not work when not run from VMR, even with --vmr</issue_title>
<issue_description>When attempting to cherry-pick from a directory to the VMR, it is not obvious that the command must be run from the VMR directory. Failure to do so will yield a somewhat cryptic error like:

fail: Cherry-pick operation failed: Could not find file 'C:\r\runtime\src\source-mappings.json'.
dbug: System.IO.FileNotFoundException: Could not find file 'C:\r\runtime\src\source-mappings.json'.

This doesn't say what it actually means: That what it thinks it's cherry-picking to is not a VMR. The error messages in this case should be very clear, and include hints. the tool has detected that the cherry-picking operation is "starting from the VMR". It should be able to tell the user that the target (current directory is not a VMR). Better yet, it would be good for the command to say something like:

info: Cherry-picking <commit> from repository (<source>) -> VMR (<expected vmr dir>)
info: Detected source mapping name: runtime
fail: Cherry-pick operation failed: Could not find file 'C:\r\runtime\src\source-mappings.json'. Are you sure that <expected vmr dir> is the VMR? Operation should be run from VMR dir or with --vmr

Furthermore, passing --vmr does not work. For example:

e C:\r\runtime --commit 19e7456131cad3ad17cd16871f928d06e7e1b391
info: Cherry-pick operation starting from repository
info: Detected mapping name: runtime
fail: Cherry-pick operation failed: Could not find file 'C:\r\runtime\src\source-mappings.json'.
dbug: System.IO.FileNotFoundException: Could not find file 'C:\r\runtime\src\source-mappings.json'.
      File name: 'C:\r\runtime\src\source-mappings.json'
         at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
         at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
         at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
         at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode)
         at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize)
         at System.IO.File.AsyncStreamReader(String path, Encoding encoding)
         at System.IO.File.InternalReadAllTextAsync(String path, Encoding encoding, CancellationToken cancellationToken)
         at Microsoft.DotNet.DarcLib.VirtualMonoRepo.SourceMappingParser.ParseMappings(String mappingFilePath) in /_/src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/SourceMappingParser.cs:line 40
         at Microsoft.DotNet.Darc.Operations.VirtualMonoRepo.CherryPickOperation.ExecuteInternalAsync() in /_/src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/CherryPickOperation.cs:line 84
         at Microsoft.DotNet.Darc.Operations.VirtualMonoRepo.CherryPickOperation.ExecuteAsync() in /_/src/Microsoft.DotNet.Darc/Darc/Operations/VirtualMonoRepo/CherryPickOperation.cs:line 49

This needs to be fixed.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…error messages

- Use _options.VmrPath (from --vmr) to determine the VMR path, fixing the bug where --vmr was ignored
- Fall back to checking --source as VMR for backward compatibility (running from repo with --source = VMR)
- Show clear error when neither --vmr nor --source points to a VMR, with hint to use --vmr or run from VMR dir
- Fix ApplyPatches to apply to vmrPath (not always current dir), enabling cherry-pick from any directory
- Add error handling for FindGitRoot failures
- Add directional log messages showing source and target with explicit paths

Co-authored-by: mmitche <8725170+mmitche@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix cherry-pick error messaging for non-VMR directory Fix darc vmr cherry-pick to honor --vmr and improve error messaging Feb 26, 2026
@premun
Copy link
Member

premun commented Feb 27, 2026

@mmitche what state is this in? Did you test it locally? Can we merge?

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.

darc vmr cherry-pick does not work when not run from VMR, even with --vmr

3 participants