Skip to content

Commit 1714d82

Browse files
authored
Merge pull request #10413 from gitbutlerapp/kv-branch-55-1
Adds but base update
2 parents 661da24 + cdf566d commit 1714d82

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

crates/but/src/base/mod.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::Path;
33
use colored::Colorize;
44
use gitbutler_branch_actions::upstream_integration::{
55
BranchStatus::{Conflicted, Empty, Integrated, SaflyUpdatable},
6+
Resolution, ResolutionApproach,
67
StackStatuses::{UpToDate, UpdatesRequired},
78
};
89
use gitbutler_project::Project;
@@ -21,9 +22,9 @@ pub enum Subcommands {
2122
}
2223

2324
pub fn handle(cmd: &Subcommands, repo_path: &Path, json: bool) -> anyhow::Result<()> {
25+
let project = Project::find_by_path(repo_path)?;
2426
match cmd {
2527
Subcommands::Check => {
26-
let project = Project::find_by_path(repo_path)?;
2728
if !json {
2829
println!("🔍 Checking base branch status...");
2930
}
@@ -101,7 +102,46 @@ pub fn handle(cmd: &Subcommands, repo_path: &Path, json: bool) -> anyhow::Result
101102
Ok(())
102103
}
103104
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+
}
105145
Ok(())
106146
}
107147
}

0 commit comments

Comments
 (0)