Skip to content

Commit

Permalink
Add integrate-upstream subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 4, 2024
1 parent 5ac5937 commit 7357d94
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/gitbutler-branch-actions/src/upstream_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ pub enum BaseBranchResolutionApproach {
HardReset,
}

#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
#[serde(tag = "type", content = "subject", rename_all = "camelCase")]
enum ResolutionApproach {
pub enum ResolutionApproach {
Rebase,
Merge,
Unapply,
Expand Down Expand Up @@ -75,11 +75,11 @@ impl BranchStatus {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Resolution {
branch_id: StackId,
pub branch_id: StackId,
/// Used to ensure a given branch hasn't changed since the UI issued the command.
#[serde(with = "gitbutler_serde::oid")]
branch_tree: git2::Oid,
approach: ResolutionApproach,
pub branch_tree: git2::Oid,
pub approach: ResolutionApproach,
}

enum IntegrationResult {
Expand Down
14 changes: 14 additions & 0 deletions crates/gitbutler-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ pub struct Args {
pub cmd: Subcommands,
}

#[derive(Debug, Clone, clap::ValueEnum)]
pub enum UpdateMode {
Rebase,
Merge,
Unapply,
Delete,
}

#[derive(Debug, clap::Subcommand)]
pub enum Subcommands {
/// Unapply the given ownership claim.
Expand All @@ -25,6 +33,12 @@ pub enum Subcommands {
/// The last line of hunks that should be removed.
to_line: u32,
},
/// Update the local workspace against an updated remote or target branch.
IntegrateUpstream {
/// Specify how all branches should be merged in.
#[clap(value_enum)]
mode: UpdateMode,
},
/// List and manipulate virtual branches.
#[clap(visible_alias = "branches")]
Branch(vbranch::Platform),
Expand Down
25 changes: 25 additions & 0 deletions crates/gitbutler-cli/src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@ pub mod ownership {
gitbutler_branch_actions::unapply_ownership(&project, &claims)
}
}

pub mod workspace {
use crate::args::UpdateMode;
use gitbutler_branch_actions::upstream_integration;
use gitbutler_project::Project;

pub fn update(project: Project, mode: UpdateMode) -> anyhow::Result<()> {
let approach = match mode {
UpdateMode::Rebase => upstream_integration::ResolutionApproach::Rebase,
UpdateMode::Merge => upstream_integration::ResolutionApproach::Merge,
UpdateMode::Unapply => upstream_integration::ResolutionApproach::Unapply,
UpdateMode::Delete => upstream_integration::ResolutionApproach::Delete,
};
let resolutions: Vec<_> = gitbutler_branch_actions::list_virtual_branches(&project)?
.0
.into_iter()
.map(|b| upstream_integration::Resolution {
branch_id: b.id,
branch_tree: b.tree,
approach,
})
.collect();
gitbutler_branch_actions::integrate_upstream(&project, &resolutions, None)
}
}
4 changes: 4 additions & 0 deletions crates/gitbutler-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ fn main() -> Result<()> {
let _op_span = tracing::info_span!("cli-op").entered();

match args.cmd {
args::Subcommands::IntegrateUpstream { mode } => {
let project = command::prepare::project_from_path(args.current_dir)?;
command::workspace::update(project, mode)
}
args::Subcommands::UnapplyOwnership {
filepath,
from_line,
Expand Down

0 comments on commit 7357d94

Please sign in to comment.