@@ -3,6 +3,7 @@ use std::path::Path;
3
3
use colored:: Colorize ;
4
4
use gitbutler_branch_actions:: upstream_integration:: {
5
5
BranchStatus :: { Conflicted , Empty , Integrated , SaflyUpdatable } ,
6
+ Resolution , ResolutionApproach ,
6
7
StackStatuses :: { UpToDate , UpdatesRequired } ,
7
8
} ;
8
9
use gitbutler_project:: Project ;
@@ -21,9 +22,9 @@ pub enum Subcommands {
21
22
}
22
23
23
24
pub fn handle ( cmd : & Subcommands , repo_path : & Path , json : bool ) -> anyhow:: Result < ( ) > {
25
+ let project = Project :: find_by_path ( repo_path) ?;
24
26
match cmd {
25
27
Subcommands :: Check => {
26
- let project = Project :: find_by_path ( repo_path) ?;
27
28
if !json {
28
29
println ! ( "🔍 Checking base branch status..." ) ;
29
30
}
@@ -101,7 +102,46 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, json: bool) -> anyhow::Result
101
102
Ok ( ( ) )
102
103
}
103
104
Subcommands :: Update => {
104
- // metrics_if_configured(app_settings, CommandName::Log, p).ok();
105
+ let status =
106
+ but_api:: virtual_branches:: upstream_integration_statuses ( project. id , None ) ?;
107
+ let resolutions = match status {
108
+ UpToDate => {
109
+ println ! ( "✅ Everything is up to date" ) ;
110
+ None
111
+ }
112
+ UpdatesRequired {
113
+ worktree_conflicts,
114
+ statuses,
115
+ } => {
116
+ if !worktree_conflicts. is_empty ( ) {
117
+ println ! (
118
+ "❗️ There are uncommitted changes in the worktree that may conflict with
119
+ the updates. Please commit or stash them and try again."
120
+ ) ;
121
+ None
122
+ } else if statuses. is_empty ( ) {
123
+ println ! ( "✅ Everything is up to date" ) ;
124
+ None
125
+ } else {
126
+ println ! ( "🔄 Updating branches..." ) ;
127
+ let mut resolutions = vec ! [ ] ;
128
+ for ( id, _status) in statuses {
129
+ let resolution = Resolution {
130
+ branch_id : id, // This is StackId
131
+ approach : ResolutionApproach :: Rebase ,
132
+ delete_integrated_branches : true ,
133
+ force_integrated_branches : vec ! [ ] ,
134
+ } ;
135
+ resolutions. push ( resolution) ;
136
+ }
137
+ Some ( resolutions)
138
+ }
139
+ }
140
+ } ;
141
+
142
+ if let Some ( resolutions) = resolutions {
143
+ but_api:: virtual_branches:: integrate_upstream ( project. id , resolutions, None ) ?;
144
+ }
105
145
Ok ( ( ) )
106
146
}
107
147
}
0 commit comments