File tree 2 files changed +32
-3
lines changed
core/src/modules/confirm_abort
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;
2
2
3
3
use input:: InputOptions ;
4
4
use parking_lot:: Mutex ;
5
- use todo_file:: TodoFile ;
5
+ use todo_file:: { TodoFile , State as TodoFileState } ;
6
6
use view:: { RenderContext , ViewData } ;
7
7
8
8
use crate :: {
@@ -35,7 +35,10 @@ impl Module for ConfirmAbort {
35
35
let mut results = Results :: new ( ) ;
36
36
match confirmed {
37
37
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
+ }
39
42
results. exit_status ( ExitStatus :: Good ) ;
40
43
} ,
41
44
Confirmed :: No => {
@@ -133,4 +136,24 @@ mod tests {
133
136
} ,
134
137
) ;
135
138
}
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
+ }
136
159
}
Original file line number Diff line number Diff line change @@ -205,6 +205,12 @@ impl TodoFile {
205
205
self . history . reset ( ) ;
206
206
}
207
207
208
+ /// Set the rebase todo file state.
209
+ #[ inline]
210
+ pub fn set_state ( & mut self , state : State ) {
211
+ self . state = state;
212
+ }
213
+
208
214
/// Load the rebase file from disk.
209
215
///
210
216
/// # Errors
@@ -235,7 +241,7 @@ impl TodoFile {
235
241
} )
236
242
. collect ( ) ;
237
243
self . set_lines ( lines?) ;
238
- self . state = detect_state ( & self . filepath ) ?;
244
+ self . set_state ( detect_state ( & self . filepath ) ?) ;
239
245
Ok ( ( ) )
240
246
}
241
247
You can’t perform that action at this time.
0 commit comments