Use merge_commute for strict commuting merges while creating staging branch#222
Use merge_commute for strict commuting merges while creating staging branch#222Avinash-Raj wants to merge 10 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Introduces a merge_commute helper to perform “commuting-safe” merges (auto-resolving certain conflicts when the final result is order-independent) and wires it into the staging-branch creation workflow to use strict commuting merges.
Changes:
- Added
scripts/merge_commute.pyto attempt safe auto-resolution of merge conflicts by checking whether edits commute. - Updated
scripts/create_staging_branch.shto usemerge_commute.pyinstead of directgit mergein compatibility testing and PR/additional-branch merges. - Added SPDX headers and ensured
python3is available in the staging-branch script.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/merge_commute.py | New Python-based merge driver that auto-resolves “commuting” conflicts and optionally auto-commits. |
| scripts/create_staging_branch.sh | Switches merge operations to merge_commute.py (strict mode) and commits when a merge is left in progress. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return None | ||
| result_lines.extend(base_lines[cursor : edit.base_start]) | ||
| if edit.kind == "insert": | ||
| result_lines.extend(edit.new_lines) | ||
| else: |
There was a problem hiding this comment.
For insert edits, cursor is never advanced. If there are multiple edits and the first one is an insert at base_start > 0, subsequent iterations will repeatedly re-append base_lines[cursor:edit.base_start], duplicating base content in the output. Fix by advancing cursor after emitting base_lines[cursor:edit.base_start] (e.g., set cursor = edit.base_start unconditionally before applying the edit), and then for non-insert edits advance to edit.base_end.
| return None | |
| result_lines.extend(base_lines[cursor : edit.base_start]) | |
| if edit.kind == "insert": | |
| result_lines.extend(edit.new_lines) | |
| else: | |
| return None | |
| # Append unchanged base lines up to the start of this edit. | |
| result_lines.extend(base_lines[cursor : edit.base_start]) | |
| # Advance cursor to the start of the edit range for all edit kinds. | |
| cursor = edit.base_start | |
| if edit.kind == "insert": | |
| # Insert does not consume any base lines; just add new lines. | |
| result_lines.extend(edit.new_lines) | |
| else: | |
| # Replace/delete consumes base lines up to base_end. |
| aborted = abort_merge(repo_root) | ||
| if not aborted: | ||
| print("warning: failed to abort merge", file=sys.stderr) | ||
| raise exc |
There was a problem hiding this comment.
raise exc resets the traceback context, making debugging harder. Use a bare raise here to preserve the original exception traceback.
| raise exc | |
| raise |
No description provided.