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

Function run_status

atomic-cli/src/commands/git/ref_mapping.rs:469–560  ·  view source on GitHub ↗

`atomic git shim status`: read-only per-view ref-mapping reconciliation report (CB-10A AC-2). Never materializes; never moves a ref.

()

Source from the content-addressed store, hash-verified

467/// `atomic git shim status`: read-only per-view ref-mapping reconciliation
468/// report (CB-10A AC-2). Never materializes; never moves a ref.
469pub(crate) fn run_status() -> CliResult<()> {
470 let root = crate::commands::find_repository_root()?;
471 let repo = Repository::open(&root).map_err(CliError::from)?;
472 let mappings = repo.list_ref_mappings().map_err(CliError::from)?;
473
474 // Also report the current workspace view when it has no mapping yet.
475 let working_copy = repo.require_working_copy_id().map_err(CliError::from)?;
476 let current_view = repo
477 .desired_view_name(working_copy)
478 .map_err(CliError::from)?;
479 let mut rows: Vec<(RefMapping, bool)> = mappings
480 .into_iter()
481 .map(|mapping| (mapping, true))
482 .collect();
483 if !rows
484 .iter()
485 .any(|(mapping, _)| mapping.view_name == current_view)
486 && repo.view_exists(&current_view).map_err(CliError::from)?
487 {
488 rows.push((unpersisted_mapping(&repo, &current_view)?, false));
489 }
490
491 if rows.is_empty() {
492 println!("no ref mappings (run 'atomic git shim reconcile' to establish one)");
493 return Ok(());
494 }
495 let git = GitRepository::open(&root).map_err(|error| CliError::GitError {
496 message: format!("cannot open Git repository: {error}"),
497 })?;
498 for (mapping, persisted) in rows {
499 let view_exists = repo
500 .view_exists(&mapping.view_name)
501 .map_err(CliError::from)?;
502 let (display_status, remediation) = if !view_exists {
503 (
504 RefSyncStatus::Unrepresentable,
505 "view no longer exists; its Git ref was left untouched. republish via 'git switch -c' or 'atomic git shim publish'",
506 )
507 } else {
508 let decision = classify_mapping_direction(&repo, &git, &mapping.view_name, &mapping)?;
509 match decision.action {
510 ThreeWayAction::Diverged => (
511 RefSyncStatus::Diverged,
512 remediation_for(RefSyncStatus::Diverged),
513 ),
514 ThreeWayAction::Import => (
515 RefSyncStatus::GitAhead,
516 remediation_for(RefSyncStatus::GitAhead),
517 ),
518 ThreeWayAction::Export => (
519 RefSyncStatus::AtomicAhead,
520 remediation_for(RefSyncStatus::AtomicAhead),
521 ),
522 ThreeWayAction::Noop => (mapping.status, remediation_for(mapping.status)),
523 ThreeWayAction::Unrepresentable => (
524 RefSyncStatus::Unrepresentable,
525 remediation_for(RefSyncStatus::Unrepresentable),
526 ),

Callers 1

runMethod · 0.85

Calls 14

find_repository_rootFunction · 0.85
openFunction · 0.85
unpersisted_mappingFunction · 0.85
remediation_forFunction · 0.85
list_ref_mappingsMethod · 0.80
desired_view_nameMethod · 0.80
view_existsMethod · 0.80
collectMethod · 0.45
into_iterMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected