@@ -47,6 +47,17 @@ fn similarity(str1: &str, str2: &str) -> f32 {
47
47
distance / biggest_len
48
48
}
49
49
50
+ fn interpret_checkout_result ( branch : & str , result : Result < ( ) , git2:: Error > ) {
51
+ match result {
52
+ Ok ( _) => {
53
+ println ! ( "Successfully checked out branch {}." , & branch) ;
54
+ }
55
+ Err ( e) => {
56
+ eprintln ! ( "An error occurred while checking out {}: {}" , & branch, e) ;
57
+ }
58
+ }
59
+ }
60
+
50
61
fn main ( ) {
51
62
let mut repository = find_repository ( ) . expect ( "Could not find a repository" ) ;
52
63
@@ -55,10 +66,8 @@ fn main() {
55
66
let mut branch_names: Vec < String > = branch_names ( & repository) . unwrap ( ) ;
56
67
57
68
if branch_names. contains ( & branch) {
58
- match checkout ( & mut repository, & branch) {
59
- Ok ( r) => { println ! ( "Successfully checked out branch {} {:?}" , & branch, r) ; }
60
- Err ( e) => { eprintln ! ( "Unable to successfully check out branch: {:?}" , e) ; }
61
- }
69
+ let result = checkout ( & mut repository, & branch) ;
70
+ interpret_checkout_result ( & branch, result) ;
62
71
} else {
63
72
branch_names. sort_by ( |a, b| {
64
73
let a_dist = similarity ( & branch, a) ;
@@ -69,9 +78,7 @@ fn main() {
69
78
70
79
let lowest_distance_branch = & branch_names[ 0 ] ;
71
80
72
- match checkout ( & mut repository, & lowest_distance_branch) {
73
- Ok ( r) => { println ! ( "Checked out branch {}: {:?}" , lowest_distance_branch, r) ; }
74
- Err ( e) => { eprintln ! ( "Error while checking out {}: {:?}" , lowest_distance_branch, e) ; }
75
- }
81
+ let result = checkout ( & mut repository, & lowest_distance_branch) ;
82
+ interpret_checkout_result ( & lowest_distance_branch, result) ;
76
83
}
77
84
}
0 commit comments