Skip to content

Resolve merge conflicts per file with configurable rules and shared r… - #269

Draft
Zubair Maalick (zmaalick) wants to merge 3 commits into
MetOffice:mainfrom
zmaalick:merge_conflict_rules
Draft

Zubair Maalick (zmaalick) wants to merge 3 commits into
MetOffice:mainfrom
zmaalick:merge_conflict_rules

Conversation

@zmaalick

@zmaalick Zubair Maalick (zmaalick) commented Dec 1, 2026 •

Copy link
Copy Markdown

…erere

PR Summary

Sci/Tech Reviewer:
Code Reviewer:

Resolve merge conflicts in get_git_sources.py file by file using configurable rules, fix the checkout --ours crash on one-sided files, and add an optional shared git rerere cache.

Sci/Tech Reviewer:
Code Reviewer:

When a suite combines many branches in dependencies.yaml, handle_merge_conflicts() currently runs git checkout --ours -- <path> on whole directories from a fixed CONFLICT_IGNORES list. This has two problems:

  • It crashes on one-sided files. If a conflicted file under an ignored path exists on only one side of the merge (modify/delete, which is common for KGO checksum files), git fails with path '...' does not have our version, and the extract task fails.
  • Only one fixed strategy. Every ignored path is resolved by keeping "ours"; list-like files such as CONTRIBUTORS.md can't combine both sides.

Changes

  • New CONFLICT_RULES setting. It takes comma-separated pattern=strategy rules, and the first match wins.
    • Strategies:
      • ours: keep the version merged so far.
      • theirs: take the version from the branch being merged.
      • union: keep the lines from both sides.
      • fail: leave the conflict for the user.
    • Patterns containing *, ? or [ are globs matched against the whole path (* also matches /). Plain patterns match that file or anything under that directory.
  • CONFLICT_IGNORES still works. It is applied as ours, checked after CONFLICT_RULES, so existing suites behave the same apart from the crash fix.
  • Default rules (used when neither setting is given): dependencies.yaml=ours,rose-stem=ours,CONTRIBUTORS.md=union. Previously CONTRIBUTORS.md was resolved as ours.
  • Per-file resolution. Each unmerged file is resolved on its own. If the chosen side has no version of the file, the file is removed instead of crashing. union on a one-sided file keeps the version that exists.
  • Optional shared rerere cache via CONFLICT_RERERE_CACHE. It enables git rerere with rr-cache linked to $CONFLICT_RERERE_CACHE/<dependency>. A resolution someone commits once in an extracted clone is then reused automatically by later extracts.
  • Rerere-resolved merges are committed. A merge left in progress with no remaining conflicts (for example, all resolved by rerere) is now committed instead of raising SubprocessRunError.
  • Error message fix. SubprocessRunError was being created with the command and return code swapped, so messages read Errorcode <command> raised when running command '<code>'.
  • Clearer conflict report. The RuntimeError listing unresolved files now starts the file list on a new line.
  • Clean-up. Removed the now-unused get_unmerged().

Notes for reviewers

  • Setting CONFLICT_RULES replaces the defaults, the same way setting CONFLICT_IGNORES already does.
  • rerere only replays content conflicts, not modify/delete conflicts. Recorded resolutions are applied by git, so a suite's reproducibility depends on the shared cache's contents.

<

Code Quality Checklist

  • I have performed a self-review of my own code
  • My code follows the project's style guidelines
  • Comments have been included that aid understanding and enhance the readability of the code
  • My changes generate no new warnings
  • All automated checks in the CI pipeline have completed successfully

Testing

  • This change has been tested appropriately (please describe)

Security Considerations

  • I have reviewed my changes for potential security issues
  • Sensitive data is properly handled (if applicable)
  • Authentication and authorisation are properly implemented (if applicable)

AI Assistance and Attribution

  • Some of the content of this change has been produced with the assistance of Generative AI tool name (e.g., Met Office Github Copilot Enterprise, Github Copilot Personal, ChatGPT GPT-4, etc) and I have followed the Simulation Systems AI policy (including attribution labels)

Sci/Tech Review

  • I understand this area of code and the changes being added
  • The proposed changes correspond to the pull request description
  • Documentation is sufficient (do documentation papers need updating)
  • Sufficient testing has been completed

(Please alert the code reviewer via a tag when you have approved the SR)

Code Review

  • All dependencies have been resolved
  • Related Issues have been properly linked and addressed
  • Code quality standards have been met
  • Tests are adequate and have passed
  • Security considerations have been addressed
  • Performance impact is acceptable

@github-actions github-actions Bot added the cla-required The CLA has not yet been signed by the author of this PR - added by GA label Dec 1, 2026
@zmaalick
Zubair Maalick (zmaalick) marked this pull request as draft December 1, 2026 14:28
@github-actions github-actions Bot added cla-signed The CLA has been signed as part of this PR - added by GA and removed cla-required The CLA has not yet been signed by the author of this PR - added by GA labels Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The CLA has been signed as part of this PR - added by GA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant