MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / guard_working_copy

Function guard_working_copy

atomic-cli/src/commands/git/guard.rs:454–513  ·  view source on GitHub ↗

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<'_>)

Source from the content-addressed store, hash-verified

452/// another guarded command. Atomic and Git handles are consumed while building
453/// owned evidence and are dropped before this function returns.
454pub(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(), &current);
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

Calls 10

observe_current_atomicFunction · 0.85
observe_gitFunction · 0.85
RepositoryClass · 0.85
git_evidenceFunction · 0.85
shim_workspace_activeFunction · 0.85
read_checkpointFunction · 0.85
classify_guardFunction · 0.85
is_bypassMethod · 0.80
as_refMethod · 0.80