Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Examples:
onto: Option<String>,
},

/// Merge the bottom PR of the current stack via GitHub
/// Merge the bottom PR via GitHub (after each merge, restacked dependents are pushed with `--force-with-lease` so `--stack` can merge the next PR cleanly)
#[command(after_help = "\
Examples:
ez merge
Expand Down
23 changes: 23 additions & 0 deletions src/cmd/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct MergeOutcome {
branch: String,
pr_number: u64,
restacked: usize,
pushed: Vec<String>,
}

fn merge_targets(state: &StackState, current: &str, stack: bool) -> Result<Vec<MergeTarget>> {
Expand Down Expand Up @@ -93,6 +94,7 @@ fn merge_branch(
let order = state.topo_order();
let current_root = git::repo_root()?;
let mut restacked = 0;
let mut restacked_for_push = Vec::<String>::new();

for branch_name in &order {
let meta = state.get_branch(branch_name)?;
Expand Down Expand Up @@ -123,6 +125,7 @@ fn merge_branch(
let meta = state.get_branch_mut(branch_name)?;
meta.parent_head = current_parent_tip;
restacked += 1;
restacked_for_push.push(branch_name.clone());
ui::info(&format!("Restacked `{branch_name}` onto `{parent}`"));
}
git::RebaseOutcome::Conflict(conflict) => {
Expand All @@ -133,12 +136,23 @@ fn merge_branch(
}
}

if !restacked_for_push.is_empty() {
for branch_name in &restacked_for_push {
let sp = ui::spinner(&format!("Pushing restacked `{branch_name}` after merge..."));
git::fetch_branch(&remote, branch_name)?;
git::push(&remote, branch_name, true)?;
sp.finish_and_clear();
ui::info(&format!("Pushed `{branch_name}`"));
}
}

state.save()?;

Ok(MergeOutcome {
branch: branch.to_string(),
pr_number,
restacked,
pushed: restacked_for_push,
})
}

Expand Down Expand Up @@ -189,22 +203,31 @@ pub fn run(method: &str, yes: bool, stack: bool) -> Result<()> {
}

let mut total_restacked = 0;
let mut total_pushed = 0usize;

for target in &targets {
let outcome = merge_branch(&mut state, &target.branch, target.pr_number, method)?;
total_restacked += outcome.restacked;
total_pushed += outcome.pushed.len();
ui::receipt(&serde_json::json!({
"cmd": "merge",
"branch": outcome.branch,
"pr_number": outcome.pr_number,
"method": method,
"stack": stack,
"restacked": outcome.restacked,
"pushed_branches": outcome.pushed,
}));
}

if total_restacked > 0 {
ui::info(&format!("Restacked {total_restacked} branch(es)"));
}
if total_pushed > 0 {
ui::info(&format!(
"Updated {total_pushed} remote branch(es) after restack"
));
}

if stack {
ui::success(&format!(
Expand Down
Loading