Skip to content

Commit b239177

Browse files
committed
gerris: Allow partial upstream failures
1 parent f565c12 commit b239177

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/git.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ mod rev_list;
1414
mod switch;
1515

1616
pub use branch::{branch, StartingPoint};
17-
pub use cherry_pick::cherry_pick;
17+
pub use cherry_pick::{cherry_pick, cherry_pick_abort};
1818
pub use commit::commit;
1919
pub use fetch::fetch;
2020
pub use log::log;

src/git/cherry_pick.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,16 @@ impl GitCmd for CherryPick {
1818
cmd.arg("cherry-pick").arg(self.commit);
1919
}
2020
}
21+
22+
#[derive(Default)]
23+
pub struct CherryPickAbort;
24+
25+
pub fn cherry_pick_abort() -> CherryPickAbort {
26+
CherryPickAbort
27+
}
28+
29+
impl GitCmd for CherryPickAbort {
30+
fn setup(self, cmd: &mut Command) {
31+
cmd.arg("cherry-pick").arg("--abort");
32+
}
33+
}

src/upstream.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,30 @@ pub async fn prepare_commits(
224224

225225
info!("created branch `{new_branch}`");
226226

227-
rev_list.lines().try_for_each(|commit| {
227+
// cherry-pick until we hit a commit we can't apply
228+
// if we hit such a commit, only error if we haven't applied any commits
229+
let mut had_successful_cherry_pick = false;
230+
for commit in rev_list.lines() {
228231
info!("cherry-picking {commit}...");
229-
git::cherry_pick(git::Commit(commit)).spawn()?;
230232

231-
maybe_prefix_cherry_picked_commit()
232-
})?;
233+
match git::cherry_pick(git::Commit(commit)).spawn() {
234+
Err(e_cherry) => {
235+
if !had_successful_cherry_pick {
236+
info!("failed on first commit");
237+
return Err(Error::Git(e_cherry))
238+
} else if let Err(e_abort) = git::cherry_pick_abort().spawn() {
239+
info!("failed to abort cherry-pick");
240+
return Err(Error::Git(e_abort))
241+
} else {
242+
info!("failed, stopping early");
243+
break
244+
}
245+
}
246+
_ => had_successful_cherry_pick = true
247+
}
248+
249+
maybe_prefix_cherry_picked_commit()?;
250+
}
233251

234252
info!("pushing branch...");
235253
git::push()

0 commit comments

Comments
 (0)