File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed
core/src/modules/confirm_abort Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use std::sync::Arc;
22
33use input:: InputOptions ;
44use parking_lot:: Mutex ;
5- use todo_file:: TodoFile ;
5+ use todo_file:: { TodoFile , State as TodoFileState } ;
66use view:: { RenderContext , ViewData } ;
77
88use crate :: {
@@ -35,7 +35,10 @@ impl Module for ConfirmAbort {
3535 let mut results = Results :: new ( ) ;
3636 match confirmed {
3737 Confirmed :: Yes => {
38- self . todo_file . lock ( ) . set_lines ( vec ! [ ] ) ;
38+ let todo_state = self . todo_file . lock ( ) . state ( ) . clone ( ) ;
39+ if todo_state != TodoFileState :: Edit {
40+ self . todo_file . lock ( ) . set_lines ( vec ! [ ] ) ;
41+ }
3942 results. exit_status ( ExitStatus :: Good ) ;
4043 } ,
4144 Confirmed :: No => {
@@ -133,4 +136,24 @@ mod tests {
133136 } ,
134137 ) ;
135138 }
139+
140+ #[ test]
141+ fn handle_event_yes_in_edit ( ) {
142+ module_test (
143+ & [ "pick aaa comment" ] ,
144+ & [ Event :: from ( MetaEvent :: Yes ) ] ,
145+ |mut test_context| {
146+ let mut todo_file = test_context. take_todo_file ( ) ;
147+ todo_file. set_state ( TodoFileState :: Edit ) ;
148+
149+ let mut module = create_confirm_abort ( todo_file) ;
150+ assert_results ! (
151+ test_context. handle_event( & mut module) ,
152+ Artifact :: Event ( Event :: from( MetaEvent :: Yes ) ) ,
153+ Artifact :: ExitStatus ( ExitStatus :: Good )
154+ ) ;
155+ assert ! ( !module. todo_file. lock( ) . is_empty( ) ) ;
156+ } ,
157+ ) ;
158+ }
136159}
Original file line number Diff line number Diff line change @@ -213,6 +213,12 @@ impl TodoFile {
213213 self . history . reset ( ) ;
214214 }
215215
216+ /// Set the rebase todo file state.
217+ #[ inline]
218+ pub fn set_state ( & mut self , state : State ) {
219+ self . state = state;
220+ }
221+
216222 /// Load the rebase file from disk.
217223 ///
218224 /// # Errors
@@ -243,7 +249,7 @@ impl TodoFile {
243249 } )
244250 . collect ( ) ;
245251 self . set_lines ( lines?) ;
246- self . state = detect_state ( & self . filepath ) ?;
252+ self . set_state ( detect_state ( & self . filepath ) ?) ;
247253 Ok ( ( ) )
248254 }
249255
You can’t perform that action at this time.
0 commit comments