Skip to content

Commit 32dbd59

Browse files
feat(move): Add --fixup to squash moved commits into the destination
1 parent 34bef06 commit 32dbd59

File tree

4 files changed

+749
-3
lines changed

4 files changed

+749
-3
lines changed

git-branchless/src/commands/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ fn do_main_and_drop_locals() -> eyre::Result<i32> {
211211
dest,
212212
base,
213213
exact,
214+
fixup,
214215
insert,
215216
move_options,
216217
} => r#move::r#move(
@@ -220,6 +221,7 @@ fn do_main_and_drop_locals() -> eyre::Result<i32> {
220221
dest,
221222
base,
222223
exact,
224+
fixup,
223225
insert,
224226
&move_options,
225227
)?,

git-branchless/src/commands/move.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub fn r#move(
6464
dest: Option<Revset>,
6565
bases: Vec<Revset>,
6666
exacts: Vec<Revset>,
67+
fixup: bool,
6768
insert: bool,
6869
move_options: &MoveOptions,
6970
) -> eyre::Result<ExitCode> {
@@ -256,7 +257,7 @@ pub fn r#move(
256257
let commits_to_move = commits_to_move.union(&union_all(
257258
&exact_components.values().cloned().collect::<Vec<_>>(),
258259
));
259-
let commits_to_move = if insert {
260+
let commits_to_move = if insert || fixup {
260261
commits_to_move.union(&dag.query().children(CommitSet::from(dest_oid))?)
261262
} else {
262263
commits_to_move
@@ -275,7 +276,18 @@ pub fn r#move(
275276

276277
let source_roots = dag.query().roots(source_oids.clone())?;
277278
for source_root in commit_set_to_vec_unsorted(&source_roots)? {
278-
builder.move_subtree(source_root, vec![dest_oid])?;
279+
if fixup {
280+
let commits = dag
281+
.query()
282+
.descendants(CommitSet::from(source_root))?
283+
.difference(&dag.obsolete_commits);
284+
let commits = commit_set_to_vec_unsorted(&commits)?;
285+
for commit in commits.iter() {
286+
builder.fixup_commit(*commit, dest_oid)?;
287+
}
288+
} else {
289+
builder.move_subtree(source_root, vec![dest_oid])?;
290+
}
279291
}
280292

281293
let component_roots: CommitSet = exact_components.keys().cloned().collect();
@@ -384,7 +396,14 @@ pub fn r#move(
384396
}
385397
}
386398

387-
builder.move_subtree(component_root, vec![component_dest_oid])?;
399+
if fixup {
400+
let commits = commit_set_to_vec_unsorted(component)?;
401+
for commit in commits.iter() {
402+
builder.fixup_commit(*commit, dest_oid)?;
403+
}
404+
} else {
405+
builder.move_subtree(component_root, vec![component_dest_oid])?;
406+
}
388407
}
389408

390409
if insert {

git-branchless/src/opts.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,10 @@ pub enum Command {
319319
#[clap(value_parser, short = 'd', long = "dest")]
320320
dest: Option<Revset>,
321321

322+
/// Combine the moved commits and squash into the destination commit.
323+
#[clap(action, short = 'F', long = "fixup", conflicts_with = "insert")]
324+
fixup: bool,
325+
322326
/// Insert the subtree between the destination and it's children, if any.
323327
/// Only supported if the moved subtree has a single head.
324328
#[clap(action, short = 'I', long = "insert")]

0 commit comments

Comments
 (0)