1- use super :: { Action , OpTrait , selected_rev } ;
1+ use super :: { Action , OpTrait } ;
22use crate :: {
33 Res ,
4- app:: { App , PromptParams , State } ,
5- item_data:: { ItemData , Ref , Rev } ,
4+ app:: { App , State } ,
5+ git,
6+ item_data:: { ItemData , Ref } ,
67 menu:: arg:: Arg ,
8+ picker:: { PickerParams , PickerState } ,
79 term:: Term ,
810} ;
911use std:: {
@@ -66,23 +68,30 @@ impl OpTrait for RebaseAbort {
6668
6769pub ( crate ) struct RebaseElsewhere ;
6870impl OpTrait for RebaseElsewhere {
69- fn get_action ( & self , _target : & ItemData ) -> Option < Action > {
71+ fn get_action ( & self , target : & ItemData ) -> Option < Action > {
72+ let default_ref = if let ItemData :: Reference { kind, .. } = target {
73+ Some ( kind. clone ( ) )
74+ } else {
75+ None
76+ } ;
77+
7078 Some ( Rc :: new ( move |app : & mut App , term : & mut Term | {
71- let rev = app. prompt (
79+ let args = app. state . pending_menu . as_ref ( ) . unwrap ( ) . args ( ) ;
80+ app. close_menu ( ) ;
81+ let result = app. pick (
7282 term,
73- & PromptParams {
74- prompt : "Rebase onto" ,
75- create_default_value : Box :: new ( |app| {
76- selected_rev ( app)
77- . as_ref ( )
78- . map ( Rev :: shorthand)
79- . map ( String :: from)
80- } ) ,
81- ..Default :: default ( )
82- } ,
83+ PickerState :: with_refs ( PickerParams {
84+ prompt : "Rebase onto" . into ( ) ,
85+ refs : & git:: branches_tags ( & app. state . repo ) ?,
86+ exclude_ref : git:: head_ref ( & app. state . repo ) ?,
87+ default : default_ref. clone ( ) . map ( crate :: item_data:: Rev :: Ref ) ,
88+ allow_custom_input : true ,
89+ } ) ,
8390 ) ?;
8491
85- rebase_elsewhere ( app, term, & rev) ?;
92+ if let Some ( data) = result {
93+ rebase_elsewhere ( app, term, data. display ( ) , & args) ?;
94+ }
8695 Ok ( ( ) )
8796 } ) )
8897 }
@@ -92,10 +101,15 @@ impl OpTrait for RebaseElsewhere {
92101 }
93102}
94103
95- fn rebase_elsewhere ( app : & mut App , term : & mut Term , rev : & str ) -> Res < ( ) > {
104+ fn rebase_elsewhere (
105+ app : & mut App ,
106+ term : & mut Term ,
107+ rev : & str ,
108+ args : & [ std:: ffi:: OsString ] ,
109+ ) -> Res < ( ) > {
96110 let mut cmd = Command :: new ( "git" ) ;
97111 cmd. arg ( "rebase" ) ;
98- cmd. args ( app . state . pending_menu . as_ref ( ) . unwrap ( ) . args ( ) ) ;
112+ cmd. args ( args) ;
99113 cmd. arg ( rev) ;
100114
101115 app. close_menu ( ) ;
0 commit comments