@@ -71,7 +71,7 @@ impl DrawableComponent for SelectBranchComponent {
71
71
)
72
72
. split ( area) [ 0 ] ;
73
73
f. render_widget (
74
- Paragraph :: new ( self . get_text ( & self . theme ) . iter ( ) )
74
+ Paragraph :: new ( self . get_text ( & self . theme ) ? . iter ( ) )
75
75
. scroll ( scroll)
76
76
. alignment ( Alignment :: Left ) ,
77
77
chunk,
@@ -162,7 +162,7 @@ impl SelectBranchComponent {
162
162
key_config : SharedKeyConfig ,
163
163
) -> Self {
164
164
Self {
165
- branch_names : Self :: get_branch_names ( ) ,
165
+ branch_names : Vec :: new ( ) ,
166
166
visible : false ,
167
167
selection : 0 ,
168
168
queue,
@@ -171,20 +171,23 @@ impl SelectBranchComponent {
171
171
}
172
172
}
173
173
/// Get all the names of the branches in the repo
174
- pub fn get_branch_names ( ) -> Vec < BranchForDisplay > {
174
+ pub fn get_branch_names ( ) -> Result < Vec < BranchForDisplay > > {
175
175
get_branches_to_display ( CWD )
176
+ . map_err ( |e| anyhow:: Error :: new ( e) )
176
177
}
177
178
178
179
///
179
180
pub fn open ( & mut self ) -> Result < ( ) > {
181
+ self . update_branches ( ) ?;
180
182
self . show ( ) ?;
181
183
182
184
Ok ( ( ) )
183
185
}
184
186
185
187
////
186
- pub fn update_branches ( & mut self ) {
187
- self . branch_names = Self :: get_branch_names ( ) ;
188
+ pub fn update_branches ( & mut self ) -> Result < ( ) > {
189
+ self . branch_names = Self :: get_branch_names ( ) ?;
190
+ Ok ( ( ) )
188
191
}
189
192
190
193
///
@@ -206,22 +209,24 @@ impl SelectBranchComponent {
206
209
}
207
210
208
211
/// Get branches to display
209
- fn get_text ( & self , theme : & SharedTheme ) -> Vec < Text > {
212
+ fn get_text ( & self , theme : & SharedTheme ) -> Result < Vec < Text > > {
210
213
let mut txt = Vec :: new ( ) ;
211
214
212
215
let max_branch_name = self
213
216
. branch_names
214
217
. iter ( )
215
218
. map ( |displaybranch| displaybranch. name . len ( ) )
216
219
. max ( )
217
- . expect ( "Failed to find max branch length" ) ;
220
+ . ok_or_else ( || anyhow:: Error :: msg (
221
+ "Couldn't get max_branch_name, is there a problem with the branches in the repo?" ,
222
+ ) ) ?;
218
223
219
224
for ( i, displaybranch) in self . branch_names . iter ( ) . enumerate ( )
220
225
{
221
226
let mut commit_message =
222
227
displaybranch. top_commit_message . clone ( ) ;
223
- if commit_message. len ( ) > 30 {
224
- commit_message. truncate ( 30 ) ;
228
+ if commit_message. len ( ) > 20 {
229
+ commit_message. truncate ( 20 ) ;
225
230
commit_message += "..." ;
226
231
}
227
232
@@ -252,13 +257,13 @@ impl SelectBranchComponent {
252
257
) ) ;
253
258
}
254
259
255
- txt
260
+ Ok ( txt)
256
261
}
257
262
258
263
///
259
264
fn switch_to_selected_branch ( & self ) {
260
265
checkout_branch (
261
- "./" ,
266
+ asyncgit :: CWD ,
262
267
& self . branch_names [ self . selection as usize ] . reference ,
263
268
)
264
269
. expect ( "Failed to checkout branch, does the branch exist?" ) ;
0 commit comments