Execute reword operation - creates new change with same content but new header. This is cleaner than going through working copy because: 1. We preserve exact same hunks/content 2. No risk of capturing unintended working copy changes 3. Works correctly even with pending changes to re-apply
(
&self,
repo: &Repository,
original_change: &Change,
message: &str,
author: Option<atomic_core::change::Author>,
pending_changes: &[Hash],
)
| 666 | /// 2. No risk of capturing unintended working copy changes |
| 667 | /// 3. Works correctly even with pending changes to re-apply |
| 668 | fn execute_reword( |
| 669 | &self, |
| 670 | repo: &Repository, |
| 671 | original_change: &Change, |
| 672 | message: &str, |
| 673 | author: Option<atomic_core::change::Author>, |
| 674 | pending_changes: &[Hash], |
| 675 | ) -> CliResult<Hash> { |
| 676 | // Build new header with updated message |
| 677 | let mut new_header = original_change.hashed.header.clone(); |
| 678 | new_header.message = message.to_string(); |
| 679 | |
| 680 | // Update author if provided |
| 681 | if let Some(new_author) = author { |
| 682 | new_header.authors = vec![new_author]; |
| 683 | } |
| 684 | |
| 685 | // Create new change with same hunks but new header |
| 686 | let new_change = Change::with_file_ops( |
| 687 | new_header, |
| 688 | original_change.hashed.hunks.clone(), |
| 689 | original_change.hashed.file_ops.clone(), |
| 690 | original_change.contents.clone(), |
| 691 | original_change.hashed.dependencies.clone(), |
| 692 | ); |
| 693 | |
| 694 | // Save the new change |
| 695 | let new_hash = repo.save_change(&new_change).map_err(|e| { |
| 696 | CliError::Internal(anyhow::anyhow!("Failed to save reworded change: {}", e)) |
| 697 | })?; |
| 698 | |
| 699 | // Insert the new change into the view (it replaces the unrecorded one) |
| 700 | repo.insert_change(&new_hash, Default::default()) |
| 701 | .map_err(|e| { |
| 702 | CliError::Internal(anyhow::anyhow!("Failed to apply reworded change: {}", e)) |
| 703 | })?; |
| 704 | |
| 705 | // Re-apply pending changes |
| 706 | if !pending_changes.is_empty() { |
| 707 | print_hint(&format!("Re-applying {} changes...", pending_changes.len())); |
| 708 | |
| 709 | for hash in pending_changes { |
| 710 | repo.reinsert_change(hash, None).map_err(|e| { |
| 711 | print_warning(&format!( |
| 712 | "Failed to re-apply change {}: {}", |
| 713 | format_hash(hash, false), |
| 714 | e |
| 715 | )); |
| 716 | CliError::Internal(anyhow::anyhow!( |
| 717 | "Failed to re-apply change {}: {}", |
| 718 | format_hash(hash, false), |
| 719 | e |
| 720 | )) |
| 721 | })?; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | Ok(new_hash) |
no test coverage detected