Skip to content

Commit 78ed33f

Browse files
authored
Merge pull request #396 from epage/fix
fix(rewrite): Always use the original HEAD
2 parents f991d46 + dcf3841 commit 78ed33f

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/rewrite/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub struct Executor {
337337
branches: Vec<(git2::Oid, String)>,
338338
delete_branches: Vec<String>,
339339
post_rewrite: Vec<(git2::Oid, git2::Oid)>,
340-
head_id: git2::Oid,
340+
head_id: Option<git2::Oid>,
341341
dry_run: bool,
342342
detached: bool,
343343
}
@@ -349,7 +349,7 @@ impl Executor {
349349
branches: Default::default(),
350350
delete_branches: Default::default(),
351351
post_rewrite: Default::default(),
352-
head_id: git2::Oid::zero(),
352+
head_id: None,
353353
dry_run,
354354
detached: false,
355355
}
@@ -362,15 +362,15 @@ impl Executor {
362362
) -> Vec<(git2::Error, &'s str, Vec<&'s str>)> {
363363
let mut failures = Vec::new();
364364

365-
self.head_id = repo.head_commit().id;
365+
self.head_id.get_or_insert_with(|| repo.head_commit().id);
366366

367367
let onto_id = script.batches[0].onto_mark();
368368
let labels = NamedLabels::new();
369369
labels.register_onto(onto_id);
370370
for (i, batch) in script.batches.iter().enumerate() {
371371
let branch_name = batch.branch().unwrap_or("detached");
372372
if !failures.is_empty() {
373-
log::trace!("Ignoring `{}`", branch_name);
373+
log::trace!("Igself.noring `{}`", branch_name);
374374
log::trace!("Script:\n{}", batch.display(&labels));
375375
continue;
376376
}
@@ -500,9 +500,9 @@ impl Executor {
500500
}
501501

502502
pub fn update_head(&mut self, old_id: git2::Oid, new_id: git2::Oid) {
503-
if self.head_id == old_id && old_id != new_id {
503+
if self.head_id.unwrap_or_else(git2::Oid::zero) == old_id && old_id != new_id {
504504
log::trace!("head changed from {} to {}", old_id, new_id);
505-
self.head_id = new_id;
505+
self.head_id = Some(new_id);
506506
}
507507
}
508508

@@ -604,10 +604,10 @@ impl Executor {
604604
if !self.dry_run && self.detached {
605605
repo.switch_branch(restore_branch)?;
606606
}
607-
} else if self.head_id != git2::Oid::zero() {
608-
log::trace!("git switch {}", self.head_id);
607+
} else if let Some(head_id) = self.head_id {
608+
log::trace!("git switch {}", head_id);
609609
if !self.dry_run && self.detached {
610-
repo.switch_commit(self.head_id)?;
610+
repo.switch_commit(head_id)?;
611611
}
612612
}
613613

0 commit comments

Comments
 (0)