@@ -32,15 +32,21 @@ fn set_upstream(upstream: String) {
3232 }
3333 } ;
3434
35- println ! ( "{}" , format_setting_upstream_message( & current_branch, & upstream) ) ;
35+ println ! (
36+ "{}" ,
37+ format_setting_upstream_message( & current_branch, & upstream)
38+ ) ;
3639
3740 // Set upstream
3841 if let Err ( msg) = set_branch_upstream ( & current_branch, & upstream) {
3942 eprintln ! ( "{}" , format_error_message( msg) ) ;
4043 return ;
4144 }
4245
43- println ! ( "{}" , format_upstream_set_message( & current_branch, & upstream) ) ;
46+ println ! (
47+ "{}" ,
48+ format_upstream_set_message( & current_branch, & upstream)
49+ ) ;
4450}
4551
4652fn show_upstream_status ( ) {
@@ -72,18 +78,21 @@ fn show_upstream_status() {
7278 let current_branch = get_current_branch ( ) . unwrap_or_default ( ) ;
7379
7480 println ! ( "{}" , format_upstream_status_header( ) ) ;
75-
81+
7682 for branch in & branches {
7783 let is_current = branch == & current_branch;
7884 let upstream = branch_upstreams. get ( branch) . unwrap ( ) ;
79-
85+
8086 match upstream {
8187 Some ( upstream_ref) => {
8288 // Check sync status
83- let sync_status = get_branch_sync_status ( branch, upstream_ref)
84- . unwrap_or_else ( |_| SyncStatus :: Unknown ) ;
85-
86- println ! ( "{}" , format_branch_with_upstream( branch, upstream_ref, & sync_status, is_current) ) ;
89+ let sync_status =
90+ get_branch_sync_status ( branch, upstream_ref) . unwrap_or ( SyncStatus :: Unknown ) ;
91+
92+ println ! (
93+ "{}" ,
94+ format_branch_with_upstream( branch, upstream_ref, & sync_status, is_current)
95+ ) ;
8796 }
8897 None => {
8998 println ! ( "{}" , format_branch_without_upstream( branch, is_current) ) ;
@@ -107,15 +116,21 @@ fn sync_all_branches(dry_run: bool, merge: bool) {
107116 return ;
108117 }
109118
110- println ! ( "{}" , format_sync_all_start_message( branches. len( ) , dry_run, merge) ) ;
119+ println ! (
120+ "{}" ,
121+ format_sync_all_start_message( branches. len( ) , dry_run, merge)
122+ ) ;
111123
112124 let mut sync_results = Vec :: new ( ) ;
113125
114126 for ( branch, upstream) in & branches {
115127 let sync_status = match get_branch_sync_status ( branch, upstream) {
116128 Ok ( status) => status,
117129 Err ( _) => {
118- sync_results. push ( ( branch. clone ( ) , SyncResult :: Error ( "Failed to get sync status" . to_string ( ) ) ) ) ;
130+ sync_results. push ( (
131+ branch. clone ( ) ,
132+ SyncResult :: Error ( "Failed to get sync status" . to_string ( ) ) ,
133+ ) ) ;
119134 continue ;
120135 }
121136 } ;
@@ -130,15 +145,20 @@ fn sync_all_branches(dry_run: bool, merge: bool) {
130145 } else {
131146 match sync_branch_with_upstream ( branch, upstream, merge) {
132147 Ok ( ( ) ) => sync_results. push ( ( branch. clone ( ) , SyncResult :: Synced ) ) ,
133- Err ( msg) => sync_results. push ( ( branch. clone ( ) , SyncResult :: Error ( msg. to_string ( ) ) ) ) ,
148+ Err ( msg) => {
149+ sync_results. push ( ( branch. clone ( ) , SyncResult :: Error ( msg. to_string ( ) ) ) )
150+ }
134151 }
135152 }
136153 }
137154 SyncStatus :: Ahead ( _) => {
138155 sync_results. push ( ( branch. clone ( ) , SyncResult :: Ahead ) ) ;
139156 }
140157 SyncStatus :: Unknown => {
141- sync_results. push ( ( branch. clone ( ) , SyncResult :: Error ( "Unknown sync status" . to_string ( ) ) ) ) ;
158+ sync_results. push ( (
159+ branch. clone ( ) ,
160+ SyncResult :: Error ( "Unknown sync status" . to_string ( ) ) ,
161+ ) ) ;
142162 }
143163 }
144164 }
@@ -150,7 +170,10 @@ fn sync_all_branches(dry_run: bool, merge: bool) {
150170 }
151171
152172 // Print summary
153- let synced_count = sync_results. iter ( ) . filter ( |( _, r) | matches ! ( r, SyncResult :: Synced | SyncResult :: WouldSync ) ) . count ( ) ;
173+ let synced_count = sync_results
174+ . iter ( )
175+ . filter ( |( _, r) | matches ! ( r, SyncResult :: Synced | SyncResult :: WouldSync ) )
176+ . count ( ) ;
154177 println ! ( "{}" , format_sync_summary( synced_count, dry_run) ) ;
155178}
156179
@@ -270,7 +293,12 @@ fn get_branch_upstream(branch: &str) -> Result<String, &'static str> {
270293// Helper function to get branch sync status
271294fn get_branch_sync_status ( branch : & str , upstream : & str ) -> Result < SyncStatus , & ' static str > {
272295 let output = Command :: new ( "git" )
273- . args ( [ "rev-list" , "--left-right" , "--count" , & format ! ( "{upstream}...{branch}" ) ] )
296+ . args ( [
297+ "rev-list" ,
298+ "--left-right" ,
299+ "--count" ,
300+ & format ! ( "{upstream}...{branch}" ) ,
301+ ] )
274302 . output ( )
275303 . map_err ( |_| "Failed to get sync status" ) ?;
276304
@@ -279,13 +307,13 @@ fn get_branch_sync_status(branch: &str, upstream: &str) -> Result<SyncStatus, &'
279307 }
280308
281309 let counts = String :: from_utf8_lossy ( & output. stdout ) ;
282- let mut parts = counts. trim ( ) . split_whitespace ( ) ;
283-
310+ let mut parts = counts. split_whitespace ( ) ;
311+
284312 let behind: u32 = parts
285313 . next ( )
286314 . and_then ( |s| s. parse ( ) . ok ( ) )
287315 . ok_or ( "Invalid sync count format" ) ?;
288-
316+
289317 let ahead: u32 = parts
290318 . next ( )
291319 . and_then ( |s| s. parse ( ) . ok ( ) )
@@ -315,7 +343,11 @@ fn get_branches_with_upstreams() -> Result<Vec<(String, String)>, &'static str>
315343}
316344
317345// Helper function to sync branch with upstream
318- fn sync_branch_with_upstream ( branch : & str , upstream : & str , merge : bool ) -> Result < ( ) , & ' static str > {
346+ fn sync_branch_with_upstream (
347+ branch : & str ,
348+ upstream : & str ,
349+ merge : bool ,
350+ ) -> Result < ( ) , & ' static str > {
319351 // Switch to the branch first
320352 let status = Command :: new ( "git" )
321353 . args ( [ "checkout" , branch] )
@@ -339,7 +371,11 @@ fn sync_branch_with_upstream(branch: &str, upstream: &str, merge: bool) -> Resul
339371 . map_err ( |_| "Failed to sync with upstream" ) ?;
340372
341373 if !status. success ( ) {
342- return Err ( if merge { "Merge failed" } else { "Rebase failed" } ) ;
374+ return Err ( if merge {
375+ "Merge failed"
376+ } else {
377+ "Rebase failed"
378+ } ) ;
343379 }
344380
345381 Ok ( ( ) )
@@ -371,7 +407,12 @@ pub fn format_upstream_status_header() -> &'static str {
371407 "🔗 Upstream status for all branches:\n "
372408}
373409
374- pub fn format_branch_with_upstream ( branch : & str , upstream : & str , sync_status : & SyncStatus , is_current : bool ) -> String {
410+ pub fn format_branch_with_upstream (
411+ branch : & str ,
412+ upstream : & str ,
413+ sync_status : & SyncStatus ,
414+ is_current : bool ,
415+ ) -> String {
375416 let current_indicator = if is_current { "* " } else { " " } ;
376417 let status_text = match sync_status {
377418 SyncStatus :: UpToDate => "✅ up-to-date" ,
@@ -380,7 +421,7 @@ pub fn format_branch_with_upstream(branch: &str, upstream: &str, sync_status: &S
380421 SyncStatus :: Diverged ( b, a) => & format ! ( "🔀 {b} behind, {a} ahead" ) ,
381422 SyncStatus :: Unknown => "❓ unknown" ,
382423 } ;
383-
424+
384425 format ! ( "{current_indicator}{branch} -> {upstream} ({status_text})" )
385426}
386427
@@ -418,8 +459,10 @@ pub fn format_sync_result_line(branch: &str, result: &SyncResult) -> String {
418459
419460pub fn format_sync_summary ( synced_count : usize , dry_run : bool ) -> String {
420461 if dry_run {
421- format ! ( "\n 💡 Would sync {synced_count} branch(es). Run without --dry-run to apply changes." )
462+ format ! (
463+ "\n 💡 Would sync {synced_count} branch(es). Run without --dry-run to apply changes."
464+ )
422465 } else {
423466 format ! ( "\n ✅ Synced {synced_count} branch(es) successfully." )
424467 }
425- }
468+ }
0 commit comments