Run one command-boundary guard without invoking status, materialization, or another guarded command. Atomic and Git handles are consumed while building owned evidence and are dropped before this function returns.
(request: GuardRequest<'_>)
| 452 | /// another guarded command. Atomic and Git handles are consumed while building |
| 453 | /// owned evidence and are dropped before this function returns. |
| 454 | pub(crate) fn guard_working_copy(request: GuardRequest<'_>) -> Result<GuardOutcome, GuardError> { |
| 455 | if request.operation.is_bypass() { |
| 456 | return Ok(GuardOutcome::Pass(Box::new(GuardPass { |
| 457 | operation: request.operation, |
| 458 | reason: GuardPassReason::Bypass, |
| 459 | old: None, |
| 460 | current: None, |
| 461 | }))); |
| 462 | } |
| 463 | |
| 464 | // `observe_current_atomic` owns and drops its read-only Repository handle. |
| 465 | let atomic: AtomicGuardEvidence = checkpoint::observe_current_atomic(request.root)?.into(); |
| 466 | // `observe_git` returns owned evidence; its libgit2 handle is local to the observer. |
| 467 | let repository = match observe_git(request.root)? { |
| 468 | GitObservation::NoGit { root } => { |
| 469 | return Ok(GuardOutcome::Pass(Box::new(GuardPass { |
| 470 | operation: request.operation, |
| 471 | reason: GuardPassReason::NoGit, |
| 472 | old: None, |
| 473 | current: Some(GuardEvidence { |
| 474 | atomic, |
| 475 | git: GuardGitEvidence::NoGit { root }, |
| 476 | }), |
| 477 | }))); |
| 478 | } |
| 479 | GitObservation::Repository(repository) => repository, |
| 480 | }; |
| 481 | let current = GuardEvidence { |
| 482 | atomic, |
| 483 | git: GuardGitEvidence::Repository(Box::new(git_evidence(&repository))), |
| 484 | }; |
| 485 | if !shim_workspace_active(request.root)? { |
| 486 | return Ok(GuardOutcome::Pass(Box::new(GuardPass { |
| 487 | operation: request.operation, |
| 488 | reason: GuardPassReason::ShimNotEnabled, |
| 489 | old: None, |
| 490 | current: Some(current), |
| 491 | }))); |
| 492 | } |
| 493 | let checkpoint = checkpoint::read_checkpoint(request.root)?; |
| 494 | let mut outcome = classify_guard(request.operation, checkpoint.as_ref(), ¤t); |
| 495 | |
| 496 | if let ( |
| 497 | GuardOutcome::Refuse(ref mut refusal), |
| 498 | WipPolicy::CaptureOrReuse { |
| 499 | workspace, |
| 500 | operation_id, |
| 501 | }, |
| 502 | ) = (&mut outcome, request.wip) |
| 503 | { |
| 504 | let recovery = capture_or_reuse_tracked_wip(WipCaptureRequest::new( |
| 505 | request.root, |
| 506 | workspace, |
| 507 | operation_id, |
| 508 | ))?; |
| 509 | refusal.recovery = Some(recovery); |
| 510 | } |
| 511 |