Skip to content

Commit

Permalink
feat(split): wire up remaining rebase/move options
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonrcarter committed Dec 18, 2024
1 parent 7ff0496 commit c6c9420
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
4 changes: 4 additions & 0 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,10 @@ pub enum Command {
/// Options for resolving revset expressions.
#[clap(flatten)]
resolve_revset_options: ResolveRevsetOptions,

/// Options for moving commits.
#[clap(flatten)]
move_options: MoveOptions,
},

/// Push commits to a remote.
Expand Down
2 changes: 2 additions & 0 deletions git-branchless/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,15 @@ fn command_main(ctx: CommandContext, opts: Opts) -> EyreExitOr<()> {
files,
resolve_revset_options,
revset,
move_options,
} => split::split(
&effects,
revset,
&resolve_revset_options,
files,
detach,
discard,
&move_options,
&git_run_info,
)?,

Expand Down
40 changes: 32 additions & 8 deletions git-branchless/src/commands/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
time::{SystemTime, UNIX_EPOCH},
};

use git_branchless_opts::{ResolveRevsetOptions, Revset};
use git_branchless_opts::{MoveOptions, ResolveRevsetOptions, Revset};
use git_branchless_revset::resolve_commits;
use lib::{
core::{
Expand Down Expand Up @@ -43,6 +43,7 @@ pub fn split(
files_to_extract: Vec<String>,
detach: bool,
discard: bool,
move_options: &MoveOptions,
git_run_info: &GitRunInfo,
) -> EyreExitOr<()> {
let repo = Repo::from_current_dir()?;
Expand All @@ -63,6 +64,16 @@ pub fn split(
let pool = ThreadPoolBuilder::new().build()?;
let repo_pool = RepoResource::new_pool(&repo)?;

let MoveOptions {
force_rewrite_public_commits,
force_in_memory,
force_on_disk,
detect_duplicate_commits_via_patch_id,
resolve_merge_conflicts,
dump_rebase_constraints,
dump_rebase_plan,
} = *move_options;

let commit_to_split_oid: NonZeroOid = match resolve_commits(
effects,
&repo,
Expand Down Expand Up @@ -91,10 +102,10 @@ pub fn split(
let permissions = match RebasePlanPermissions::verify_rewrite_set(
&dag,
BuildRebasePlanOptions {
force_rewrite_public_commits: false,
dump_rebase_constraints: false,
dump_rebase_plan: false,
detect_duplicate_commits_via_patch_id: false,
force_rewrite_public_commits,
dump_rebase_constraints,
dump_rebase_plan,
detect_duplicate_commits_via_patch_id,
},
&vec![commit_to_split_oid].into_iter().collect(),
)? {
Expand Down Expand Up @@ -271,6 +282,19 @@ pub fn split(
Some(extracted_commit_oid)
};

// push the new commits into the dag for the rebase planner
dag.sync_from_oids(
&effects,

Check failure on line 287 in git-branchless/src/commands/split.rs

View workflow job for this annotation

GitHub Actions / static-analysis

this expression creates a reference which is immediately dereferenced by the compiler
&repo,
CommitSet::empty(),
match extracted_commit_oid {
None => CommitSet::from(split_commit_oid),
Some(extracted_commit_oid) => vec![split_commit_oid, extracted_commit_oid]
.into_iter()
.collect(),
},
)?;

let head_info = repo.get_head_info()?;
let (checkout_target, rewritten_oids) = match head_info {
// branch @ split commit checked out: extend branch to include extracted
Expand Down Expand Up @@ -352,9 +376,9 @@ pub fn split(
now,
event_tx_id,
preserve_timestamps: get_restack_preserve_timestamps(&repo)?,
force_in_memory: true,
force_on_disk: false,
resolve_merge_conflicts: false,
force_in_memory,
force_on_disk,
resolve_merge_conflicts,
check_out_commit_options: CheckOutCommitOptions {
additional_args: Default::default(),
force_detach: false,
Expand Down

0 comments on commit c6c9420

Please sign in to comment.