(
root: &Path,
ref_name: &str,
commit_oid: &str,
)
| 504 | } |
| 505 | |
| 506 | fn create_recovery_ref( |
| 507 | root: &Path, |
| 508 | ref_name: &str, |
| 509 | commit_oid: &str, |
| 510 | ) -> Result<(), WipCaptureError> { |
| 511 | let object_format = git_text( |
| 512 | root, |
| 513 | "read Git object format", |
| 514 | &os_args(&["rev-parse", "--show-object-format"]), |
| 515 | None, |
| 516 | None, |
| 517 | )?; |
| 518 | let zero_oid = match object_format.as_str() { |
| 519 | "sha1" => "0".repeat(40), |
| 520 | "sha256" => "0".repeat(64), |
| 521 | format => { |
| 522 | return Err(WipCaptureError::UnsupportedObjectFormat { |
| 523 | format: format.to_string(), |
| 524 | }) |
| 525 | } |
| 526 | }; |
| 527 | let args = vec![ |
| 528 | OsString::from("update-ref"), |
| 529 | OsString::from("--create-reflog"), |
| 530 | OsString::from("-m"), |
| 531 | OsString::from(RECOVERY_REFLOG_MESSAGE), |
| 532 | OsString::from(ref_name), |
| 533 | OsString::from(commit_oid), |
| 534 | OsString::from(zero_oid), |
| 535 | ]; |
| 536 | let output = run_git_raw(root, "create WIP recovery ref", &args, None, None)?; |
| 537 | if output.status.success() { |
| 538 | return Ok(()); |
| 539 | } |
| 540 | if resolve_ref(root, ref_name)?.is_some() { |
| 541 | return Err(WipCaptureError::RefAlreadyExists { |
| 542 | ref_name: ref_name.to_string(), |
| 543 | }); |
| 544 | } |
| 545 | Err(command_failure("create WIP recovery ref", &output)) |
| 546 | } |
| 547 | |
| 548 | fn resolve_ref(root: &Path, ref_name: &str) -> Result<Option<String>, WipCaptureError> { |
| 549 | let args = vec![ |
no test coverage detected