Skip to content

Commit 7357d94

Browse files
committed
Add integrate-upstream subcommand
1 parent 5ac5937 commit 7357d94

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

crates/gitbutler-branch-actions/src/upstream_integration.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ pub enum BaseBranchResolutionApproach {
4141
HardReset,
4242
}
4343

44-
#[derive(Serialize, Deserialize, PartialEq, Debug)]
44+
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
4545
#[serde(tag = "type", content = "subject", rename_all = "camelCase")]
46-
enum ResolutionApproach {
46+
pub enum ResolutionApproach {
4747
Rebase,
4848
Merge,
4949
Unapply,
@@ -75,11 +75,11 @@ impl BranchStatus {
7575
#[derive(Serialize, Deserialize, PartialEq, Debug)]
7676
#[serde(rename_all = "camelCase")]
7777
pub struct Resolution {
78-
branch_id: StackId,
78+
pub branch_id: StackId,
7979
/// Used to ensure a given branch hasn't changed since the UI issued the command.
8080
#[serde(with = "gitbutler_serde::oid")]
81-
branch_tree: git2::Oid,
82-
approach: ResolutionApproach,
81+
pub branch_tree: git2::Oid,
82+
pub approach: ResolutionApproach,
8383
}
8484

8585
enum IntegrationResult {

crates/gitbutler-cli/src/args.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ pub struct Args {
1414
pub cmd: Subcommands,
1515
}
1616

17+
#[derive(Debug, Clone, clap::ValueEnum)]
18+
pub enum UpdateMode {
19+
Rebase,
20+
Merge,
21+
Unapply,
22+
Delete,
23+
}
24+
1725
#[derive(Debug, clap::Subcommand)]
1826
pub enum Subcommands {
1927
/// Unapply the given ownership claim.
@@ -25,6 +33,12 @@ pub enum Subcommands {
2533
/// The last line of hunks that should be removed.
2634
to_line: u32,
2735
},
36+
/// Update the local workspace against an updated remote or target branch.
37+
IntegrateUpstream {
38+
/// Specify how all branches should be merged in.
39+
#[clap(value_enum)]
40+
mode: UpdateMode,
41+
},
2842
/// List and manipulate virtual branches.
2943
#[clap(visible_alias = "branches")]
3044
Branch(vbranch::Platform),

crates/gitbutler-cli/src/command/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,28 @@ pub mod ownership {
6060
gitbutler_branch_actions::unapply_ownership(&project, &claims)
6161
}
6262
}
63+
64+
pub mod workspace {
65+
use crate::args::UpdateMode;
66+
use gitbutler_branch_actions::upstream_integration;
67+
use gitbutler_project::Project;
68+
69+
pub fn update(project: Project, mode: UpdateMode) -> anyhow::Result<()> {
70+
let approach = match mode {
71+
UpdateMode::Rebase => upstream_integration::ResolutionApproach::Rebase,
72+
UpdateMode::Merge => upstream_integration::ResolutionApproach::Merge,
73+
UpdateMode::Unapply => upstream_integration::ResolutionApproach::Unapply,
74+
UpdateMode::Delete => upstream_integration::ResolutionApproach::Delete,
75+
};
76+
let resolutions: Vec<_> = gitbutler_branch_actions::list_virtual_branches(&project)?
77+
.0
78+
.into_iter()
79+
.map(|b| upstream_integration::Resolution {
80+
branch_id: b.id,
81+
branch_tree: b.tree,
82+
approach,
83+
})
84+
.collect();
85+
gitbutler_branch_actions::integrate_upstream(&project, &resolutions, None)
86+
}
87+
}

crates/gitbutler-cli/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ fn main() -> Result<()> {
1717
let _op_span = tracing::info_span!("cli-op").entered();
1818

1919
match args.cmd {
20+
args::Subcommands::IntegrateUpstream { mode } => {
21+
let project = command::prepare::project_from_path(args.current_dir)?;
22+
command::workspace::update(project, mode)
23+
}
2024
args::Subcommands::UnapplyOwnership {
2125
filepath,
2226
from_line,

0 commit comments

Comments
 (0)