@@ -5,6 +5,7 @@ use gitbutler_branch_actions::upstream_integration::{
55 StackStatuses :: { UpToDate , UpdatesRequired } ,
66} ;
77use gitbutler_project:: Project ;
8+ use std:: io:: Write ;
89
910#[ derive( Debug , clap:: Parser ) ]
1011pub struct Platform {
@@ -20,23 +21,27 @@ pub enum Subcommands {
2021}
2122
2223pub fn handle ( cmd : Subcommands , project : & Project , json : bool ) -> anyhow:: Result < ( ) > {
24+ let mut stdout = std:: io:: stdout ( ) ;
2325 match cmd {
2426 Subcommands :: Check => {
2527 if !json {
26- println ! ( "🔍 Checking base branch status..." ) ;
28+ writeln ! ( stdout , "🔍 Checking base branch status..." ) . ok ( ) ;
2729 }
2830 let base_branch = but_api:: virtual_branches:: fetch_from_remotes (
2931 project. id ,
3032 Some ( "auto" . to_string ( ) ) ,
3133 ) ?;
32- println ! ( "\n 📍 Base branch:\t \t {}" , base_branch. branch_name) ;
33- println ! (
34+ writeln ! ( stdout, "\n 📍 Base branch:\t \t {}" , base_branch. branch_name) . ok ( ) ;
35+ writeln ! (
36+ stdout,
3437 "⏫ Upstream commits:\t {} new commits on {}\n " ,
3538 base_branch. behind, base_branch. branch_name
36- ) ;
39+ )
40+ . ok ( ) ;
3741 let commits = base_branch. recent_commits . iter ( ) . take ( 3 ) ;
3842 for commit in commits {
39- println ! (
43+ writeln ! (
44+ stdout,
4045 "\t {} {}" ,
4146 & commit. id[ ..7 ] ,
4247 & commit
@@ -46,29 +51,34 @@ pub fn handle(cmd: Subcommands, project: &Project, json: bool) -> anyhow::Result
4651 . chars( )
4752 . take( 72 )
4853 . collect:: <String >( )
49- ) ;
54+ )
55+ . ok ( ) ;
5056 }
5157 let hidden_commits = base_branch. behind . saturating_sub ( 3 ) ;
5258 if hidden_commits > 0 {
53- println ! ( "\t ... ({hidden_commits} more - run `but base check --all` to see all)" ) ;
59+ writeln ! (
60+ stdout,
61+ "\t ... ({hidden_commits} more - run `but base check --all` to see all)"
62+ )
63+ . ok ( ) ;
5464 }
5565
5666 let status =
5767 but_api:: virtual_branches:: upstream_integration_statuses ( project. id , None ) ?;
5868
5969 match status {
60- UpToDate => println ! ( "\n ✅ Everything is up to date" ) ,
70+ UpToDate => _ = writeln ! ( stdout , "\n ✅ Everything is up to date" ) . ok ( ) ,
6171 UpdatesRequired {
6272 worktree_conflicts,
6373 statuses,
6474 } => {
6575 if !worktree_conflicts. is_empty ( ) {
66- println ! (
76+ writeln ! ( stdout ,
6777 "\n ❗️ There are uncommitted changes in the worktree that may conflict with the updates."
68- ) ;
78+ ) . ok ( ) ;
6979 }
7080 if !statuses. is_empty ( ) {
71- println ! ( "\n {}" , "Active Branch Status" . bold( ) ) ;
81+ writeln ! ( stdout , "\n {}" , "Active Branch Status" . bold( ) ) . ok ( ) ;
7282 for ( _id, status) in statuses {
7383 for bs in status. branch_statuses {
7484 let status_icon = match bs. status {
@@ -95,39 +105,45 @@ pub fn handle(cmd: Subcommands, project: &Project, json: bool) -> anyhow::Result
95105 }
96106 Empty => "Nothing to do" . normal ( ) ,
97107 } ;
98- println ! ( "\n {} {} ({})" , status_icon, bs. name, status_text) ;
108+ writeln ! ( stdout, "\n {} {} ({})" , status_icon, bs. name, status_text)
109+ . ok ( ) ;
99110 }
100111 }
101112 }
102113 }
103114 }
104- println ! ( "\n Run `but base update` to update your branches" ) ;
115+ writeln ! ( stdout , "\n Run `but base update` to update your branches" ) . ok ( ) ;
105116 Ok ( ( ) )
106117 }
107118 Subcommands :: Update => {
108119 let status =
109120 but_api:: virtual_branches:: upstream_integration_statuses ( project. id , None ) ?;
110121 let resolutions = match status {
111122 UpToDate => {
112- println ! ( "✅ Everything is up to date" ) ;
123+ writeln ! ( stdout , "✅ Everything is up to date" ) . ok ( ) ;
113124 None
114125 }
115126 UpdatesRequired {
116127 worktree_conflicts,
117128 statuses,
118129 } => {
119130 if !worktree_conflicts. is_empty ( ) {
120- println ! (
131+ writeln ! ( stdout ,
121132 "❗️ There are uncommitted changes in the worktree that may conflict with
122133 the updates. Please commit or stash them and try again."
123- ) ;
134+ )
135+ . ok ( ) ;
124136 None
125137 } else {
126- println ! ( "🔄 Updating branches..." ) ;
138+ writeln ! ( stdout , "🔄 Updating branches..." ) . ok ( ) ;
127139 let mut resolutions = vec ! [ ] ;
128140 for ( maybe_stack_id, status) in statuses {
129141 let Some ( stack_id) = maybe_stack_id else {
130- println ! ( "No stack ID, assuming we're on single-branch mode..." , ) ;
142+ writeln ! (
143+ stdout,
144+ "No stack ID, assuming we're on single-branch mode..." ,
145+ )
146+ . ok ( ) ;
131147 continue ;
132148 } ;
133149 let approach = if status
0 commit comments