Skip to content

Commit 3d516fd

Browse files
committed
updates
1 parent baeb785 commit 3d516fd

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/main.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn status(state: State, repo: &str, orig_branch: &str) -> Result<()> {
291291
}
292292

293293
fn restack(
294-
state: State,
294+
mut state: State,
295295
repo: &str,
296296
run_version: String,
297297
restack_branch: Option<String>,
@@ -335,18 +335,16 @@ fn restack(
335335
if let Some(lkg_parent) = branch.lkg_parent.as_deref() {
336336
tracing::info!("LKG parent: {}", lkg_parent);
337337
if is_ancestor(lkg_parent, &source)? {
338+
let patch_rev = format!("{}..{}", &lkg_parent, &branch.name);
339+
tracing::info!("Creating patch {}", &patch_rev);
338340
// The branch is still on top of the LKG parent. Let's create a format-patch of the
339341
// difference, and apply it on top of the new parent.
340-
let format_patch = run_git(&[
341-
"format-patch",
342-
"--stdout",
343-
&format!("{}..{}", &parent, &branch.name),
344-
])?
345-
.output();
342+
let format_patch = run_git(&["format-patch", "--stdout", &patch_rev])?.output();
346343
run_git(&["checkout", "-B", &branch.name, &parent])?;
347344
let Some(format_patch) = format_patch else {
348345
bail!("No diff between LKG and branch?! Might need to handle this case.");
349346
};
347+
tracing::info!("Applying patch...");
350348
let rebased = run_git_status(&["am", "--3way"], Some(&format_patch))?.success();
351349
if !rebased {
352350
eprintln!(
@@ -362,6 +360,11 @@ fn restack(
362360
}
363361
git_push(&branch.name)?;
364362
continue;
363+
} else {
364+
tracing::info!(
365+
"Branch '{}' is not on top of the LKG parent. Falling through to `git rebase`...",
366+
branch.name
367+
);
365368
}
366369
}
367370
run_git(&["checkout", &branch.name])?;
@@ -387,11 +390,12 @@ fn restack(
387390
restack_branch
388391
);
389392
tracing::info!("Done.");
393+
state.refresh_lkgs(repo)?;
390394
Ok(())
391395
}
392396

393397
fn git_push(branch: &str) -> Result<()> {
394-
if !shas_match(&format!("origin/{}", branch), &branch) {
398+
if !shas_match(&format!("origin/{}", branch), branch) {
395399
run_git(&["push", "-fu", "origin", &format!("{}:{}", branch, branch)])?;
396400
}
397401
Ok(())

0 commit comments

Comments
 (0)