@@ -33,7 +33,10 @@ use crate::{
3333 CliId ,
3434 command:: legacy:: {
3535 reword:: get_branch_name_from_editor,
36- rub:: RubOperationDiscriminants ,
36+ rub:: {
37+ RubOperation , RubOperationDiscriminants , StackToCommitOperation ,
38+ UnassignedToCommitOperation ,
39+ } ,
3740 status:: {
3841 CommitLineContent , FileLineContent , StatusFlags , StatusOutputLine , TuiLaunchOptions ,
3942 output:: BranchLineContent ,
@@ -724,6 +727,9 @@ impl App {
724727 terminal_area,
725728 ) ;
726729 }
730+ Message :: Amend => {
731+ self . handle_amend ( ctx) ?;
732+ }
727733 }
728734
729735 self . ensure_cursor_visible ( visible_height) ;
@@ -2689,6 +2695,57 @@ impl App {
26892695 let details_viewport = self . details_viewport ( terminal_area) ;
26902696 self . details . ensure_selection_visible ( details_viewport) ;
26912697 }
2698+
2699+ fn handle_amend ( & mut self , ctx : & mut Context ) -> anyhow:: Result < ( ) > {
2700+ let Some ( selection) = self
2701+ . cursor
2702+ . selected_line ( & self . status_lines )
2703+ . and_then ( |line| line. data . cli_id ( ) )
2704+ else {
2705+ return Ok ( ( ) ) ;
2706+ } ;
2707+
2708+ let CliId :: Commit { commit_id, .. } = & * * selection else {
2709+ return Ok ( ( ) ) ;
2710+ } ;
2711+
2712+ let stack_id = {
2713+ let ( _guard, _, ws, _) = ctx. workspace_and_db ( ) ?;
2714+ ws. find_commit_and_containers ( * commit_id)
2715+ . and_then ( |( stack, _, _) | stack. id )
2716+ } ;
2717+
2718+ let ( operation, confirm_message) = if let Some ( stack_id) = stack_id
2719+ && operations:: stack_has_assigned_changes ( ctx, stack_id) ?
2720+ {
2721+ (
2722+ RubOperation :: StackToCommit ( StackToCommitOperation {
2723+ from : stack_id,
2724+ to : * commit_id,
2725+ } ) ,
2726+ format ! (
2727+ "Amend changes assigned to stack into {}?" ,
2728+ commit_id. to_hex_with_len( 7 )
2729+ ) ,
2730+ )
2731+ } else {
2732+ (
2733+ RubOperation :: UnassignedToCommit ( UnassignedToCommitOperation { oid : * commit_id } ) ,
2734+ format ! ( "Amend unassigned into {}?" , commit_id. to_hex_with_len( 7 ) ) ,
2735+ )
2736+ } ;
2737+
2738+ self . confirm = Some ( Confirm :: new (
2739+ confirm_message,
2740+ run_after_confirmation_msg ( move |_, ctx, messages| {
2741+ let what_to_select = operations:: rub ( ctx, & operation) ?;
2742+ messages. push ( Message :: Reload ( what_to_select) ) ;
2743+ Ok ( ( ) )
2744+ } ) ,
2745+ ) ) ;
2746+
2747+ Ok ( ( ) )
2748+ }
26922749}
26932750
26942751fn event_to_messages ( ev : Event , key_binds : & KeyBinds , mode : & Mode , messages : & mut Vec < Message > ) {
@@ -2775,6 +2832,7 @@ enum Message {
27752832 EnterDetailsMode ,
27762833 LeaveDetailsMode ,
27772834 NewBranch ,
2835+ Amend ,
27782836
27792837 // Utilities
27802838 CopySelection ,
0 commit comments