-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix: preserve line order when staging non-contiguous lines in change blocks #5120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 fixes a bug in patch transformation where staging non-contiguous lines within change blocks (multiple consecutive deletions followed by additions) would not preserve the correct line order. The fix introduces special handling for change blocks to ensure that selected deletions and additions are kept together as pairs, while unselected deletions are converted to context lines.
Key Changes:
- Added logic to detect and handle change blocks (multiple consecutive deletions) as a unit
- Selected deletions and additions are now processed together before appending unselected lines as context
- New test case validates that non-contiguous selection preserves change pair relationships
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/commands/patch/transform.go | Implemented change block detection and special handling for non-contiguous line selection in the transformHunkLines function |
| pkg/commands/patch/patch_test.go | Added test case TestTransformNonContiguousSelection to verify correct behavior when selecting non-contiguous lines in change blocks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
modified: pkg/commands/patch/patch_test.go modified: pkg/commands/patch/transform.go
4a79153 to
3549de8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@stefanhaller mind taking a look? |
Fixes #5103
When you have a diff with consecutive deletions followed by additions (like renaming a variable across multiple lines), and you try to stage only some of them (e.g., first deletion + first addition), the resulting patch had lines in the wrong order.
The problem was that unselected deletions were being converted to context lines immediately, causing them to appear between the selected deletion and addition. Now we defer those context lines until after all additions in the block.
Before:
After: