| 420 | return false; |
| 421 | }; |
| 422 | fn checkpoint( |
| 423 | git: &git2::Repository, |
| 424 | state: &GitStateRef, |
| 425 | template: &GitBoundaryCheckpoint, |
| 426 | ) -> Option<GitBoundaryCheckpoint> { |
| 427 | let (oid, symref) = match &state.head { |
| 428 | GitHeadState::Attached { symref, oid } => (oid, Some(symref.clone())), |
| 429 | GitHeadState::Detached { oid } => (oid, None), |
| 430 | _ => return None, |
| 431 | }; |
| 432 | let hex = |oid: &atomic_core::operation::GitObjectId| { |
| 433 | oid.as_bytes() |
| 434 | .iter() |
| 435 | .map(|b| format!("{b:02x}")) |
| 436 | .collect::<String>() |
| 437 | }; |
| 438 | let mut checkpoint = template.clone(); |
| 439 | checkpoint.head_oid = Some(hex(oid)); |
| 440 | checkpoint.head_symref = symref; |
| 441 | // Before publication the index may contain partial staging. HEAD's |
| 442 | // tree must come from its commit, independently of the index tree. |
| 443 | checkpoint.head_tree = Some( |
| 444 | git.find_commit(git2::Oid::from_bytes(oid.as_bytes()).ok()?) |
| 445 | .ok()? |
| 446 | .tree_id() |
| 447 | .to_string(), |
| 448 | ); |
| 449 | Some(checkpoint) |
| 450 | } |
| 451 | let Ok(git) = git2::Repository::discover(repo.root()) else { |
| 452 | return false; |
| 453 | }; |