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

Function project_atomic_to_git

atomic-cli/src/commands/git/shim.rs:2957–3047  ·  view source on GitHub ↗
(
    root: &Path,
    repo: &Repository,
    working_copy: WorkingCopyId,
    git: &GitRepository,
    current: &ShimSnapshot,
)

Source from the content-addressed store, hash-verified

2955
2956#[tracing::instrument(name = "export", skip_all)]
2957pub(crate) fn project_atomic_to_git(
2958 root: &Path,
2959 repo: &Repository,
2960 working_copy: WorkingCopyId,
2961 git: &GitRepository,
2962 current: &ShimSnapshot,
2963) -> CliResult<()> {
2964 let head = git
2965 .head()
2966 .map_err(|error| git_error(format!("Git HEAD is unavailable: {error}")))?;
2967 if !head.is_branch() {
2968 return Err(git_error("Git HEAD must be attached to a local branch"));
2969 }
2970 let branch = head
2971 .shorthand()
2972 .map_err(|error| git_error(format!("Git branch name is not valid UTF-8: {error}")))?;
2973 let desired_view = repo
2974 .desired_view_name(working_copy)
2975 .map_err(CliError::from)?;
2976 if branch != desired_view {
2977 return Err(git_error(format!(
2978 "Git branch '{branch}' does not match current Atomic view '{desired_view}'"
2979 )));
2980 }
2981
2982 let atomic_status = repo
2983 .status(working_copy, StatusOptions::default())
2984 .map_err(CliError::from)?;
2985 if !atomic_status.is_clean() {
2986 return Err(git_error("Atomic working copy is not clean"));
2987 }
2988 require_clean_git_index(git)?;
2989
2990 // Build and verify the complete graph-derived projection before creating
2991 // any Git object, commit, ref, or index mutation. The Git index may still
2992 // describe the old HEAD on an Atomic→Git reconcile, so only the worktree
2993 // layer is applicable until the new tree is published.
2994 let policy = conversion_policy(git)?;
2995 let project = repo
2996 .project_tree(&desired_view, &policy)
2997 .map_err(|error| git_error(format!("cannot build complete Atomic projection: {error}")))?;
2998 let index = observe_git_index(root, &policy)
2999 .map_err(|error| git_error(format!("cannot observe Git index: {error}")))?;
3000 let filter = GitAttributesFilter::for_repository(root);
3001 let worktree = observe_worktree(root, Some(&index), &filter, &policy)
3002 .map_err(|error| git_error(format!("cannot observe Git worktree: {error}")))?;
3003 let report = compare_project_to_worktree_with_index(&project, &worktree, &index, &policy);
3004 if !report.is_equivalent() {
3005 return Err(equivalence_error("Atomic-to-Git shim projection", &report));
3006 }
3007 let tree_oid = write_project_tree(git, &project)?;
3008 let tree = git
3009 .find_tree(tree_oid)
3010 .map_err(|error| git_error(format!("cannot read projected Git tree: {error}")))?;
3011 let parent = head
3012 .peel_to_commit()
3013 .map_err(|error| git_error(format!("cannot read Git HEAD commit: {error}")))?;
3014 let signature = projection_signature(git)?;

Callers 2

enable_anchor_innerFunction · 0.85

Calls 15

require_clean_git_indexFunction · 0.85
conversion_policyFunction · 0.85
observe_git_indexFunction · 0.85
observe_worktreeFunction · 0.85
equivalence_errorFunction · 0.85
projection_signatureFunction · 0.85
journal_and_move_branchFunction · 0.85
desired_view_nameMethod · 0.80
project_treeMethod · 0.80
is_equivalentMethod · 0.80
git_errorFunction · 0.70

Tested by

no test coverage detected