Skip to content

Commit

Permalink
feat(move): Add --fixup to squash moved commits into the destination
Browse files Browse the repository at this point in the history
This only implements in-memory rebases/fixups. On-disk rebases can come later.
  • Loading branch information
claytonrcarter committed Aug 11, 2023
1 parent 7ab4cdd commit 3ad2f74
Show file tree
Hide file tree
Showing 4 changed files with 1,396 additions and 3 deletions.
22 changes: 19 additions & 3 deletions git-branchless-move/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn r#move(
exacts: Vec<Revset>,
resolve_revset_options: &ResolveRevsetOptions,
move_options: &MoveOptions,
fixup: bool,
insert: bool,
) -> EyreExitOr<()> {
let sources_provided = !sources.is_empty();
Expand Down Expand Up @@ -278,7 +279,7 @@ pub fn r#move(
let commits_to_move = commits_to_move.union(&union_all(
&exact_components.values().cloned().collect::<Vec<_>>(),
));
let commits_to_move = if insert {
let commits_to_move = if insert || fixup {
commits_to_move.union(&dag.query_children(CommitSet::from(dest_oid))?)
} else {
commits_to_move
Expand All @@ -297,7 +298,15 @@ pub fn r#move(

let source_roots = dag.query_roots(source_oids.clone())?;
for source_root in dag.commit_set_to_vec(&source_roots)? {
builder.move_subtree(source_root, vec![dest_oid])?;
if fixup {
let commits = dag.query_descendants(CommitSet::from(source_root))?;
let commits = dag.commit_set_to_vec(&commits)?;
for commit in commits.iter() {
builder.fixup_commit(*commit, dest_oid)?;
}
} else {
builder.move_subtree(source_root, vec![dest_oid])?;
}
}

let component_roots: CommitSet = exact_components.keys().cloned().collect();
Expand Down Expand Up @@ -394,7 +403,14 @@ pub fn r#move(
}
}

builder.move_subtree(component_root, vec![component_dest_oid])?;
if fixup {
let commits = dag.commit_set_to_vec(component)?;
for commit in commits.iter() {
builder.fixup_commit(*commit, dest_oid)?;
}
} else {
builder.move_subtree(component_root, vec![component_dest_oid])?;
}
}

if insert {
Expand Down
4 changes: 4 additions & 0 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ pub enum Command {
#[clap(flatten)]
move_options: MoveOptions,

/// Combine the moved commits and squash them into the destination commit.
#[clap(action, short = 'F', long = "fixup", conflicts_with = "insert")]
fixup: bool,

/// Insert the subtree between the destination and it's children, if any.
/// Only supported if the moved subtree has a single head.
#[clap(action, short = 'I', long = "insert")]
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 @@ -93,6 +93,7 @@ fn command_main(ctx: CommandContext, opts: Opts) -> EyreExitOr<()> {
exact,
resolve_revset_options,
move_options,
fixup,
insert,
} => git_branchless_move::r#move(
&effects,
Expand All @@ -103,6 +104,7 @@ fn command_main(ctx: CommandContext, opts: Opts) -> EyreExitOr<()> {
exact,
&resolve_revset_options,
&move_options,
fixup,
insert,
)?,

Expand Down
Loading

0 comments on commit 3ad2f74

Please sign in to comment.