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
  • Loading branch information
claytonrcarter committed Sep 22, 2022
1 parent 2895bc9 commit c2de030
Show file tree
Hide file tree
Showing 4 changed files with 755 additions and 3 deletions.
2 changes: 2 additions & 0 deletions git-branchless/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ fn do_main_and_drop_locals() -> eyre::Result<i32> {
dest,
base,
exact,
fixup,
insert,
move_options,
} => r#move::r#move(
Expand All @@ -220,6 +221,7 @@ fn do_main_and_drop_locals() -> eyre::Result<i32> {
dest,
base,
exact,
fixup,
insert,
&move_options,
)?,
Expand Down
25 changes: 22 additions & 3 deletions git-branchless/src/commands/move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn r#move(
dest: Option<Revset>,
bases: Vec<Revset>,
exacts: Vec<Revset>,
fixup: bool,
insert: bool,
move_options: &MoveOptions,
) -> eyre::Result<ExitCode> {
Expand Down Expand Up @@ -256,7 +257,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 @@ -275,7 +276,18 @@ pub fn r#move(

let source_roots = dag.query().roots(source_oids.clone())?;
for source_root in commit_set_to_vec_unsorted(&source_roots)? {
builder.move_subtree(source_root, vec![dest_oid])?;
if fixup {
let commits = dag
.query()
.descendants(CommitSet::from(source_root))?
.difference(&dag.obsolete_commits);
let commits = commit_set_to_vec_unsorted(&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 @@ -384,7 +396,14 @@ pub fn r#move(
}
}

builder.move_subtree(component_root, vec![component_dest_oid])?;
if fixup {
let commits = commit_set_to_vec_unsorted(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/src/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ pub enum Command {
#[clap(value_parser, short = 'd', long = "dest")]
dest: Option<Revset>,

/// Combine the moved commits and squash 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
Loading

0 comments on commit c2de030

Please sign in to comment.