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:2913–3003  ·  view source on GitHub ↗
(
    root: &Path,
    repo: &Repository,
    working_copy: WorkingCopyId,
    git: &GitRepository,
    current: &ShimSnapshot,
)

Source from the content-addressed store, hash-verified

2911
2912#[tracing::instrument(name = "export", skip_all)]
2913pub(crate) fn project_atomic_to_git(
2914 root: &Path,
2915 repo: &Repository,
2916 working_copy: WorkingCopyId,
2917 git: &GitRepository,
2918 current: &ShimSnapshot,
2919) -> CliResult<()> {
2920 let head = git
2921 .head()
2922 .map_err(|error| git_error(format!("Git HEAD is unavailable: {error}")))?;
2923 if !head.is_branch() {
2924 return Err(git_error("Git HEAD must be attached to a local branch"));
2925 }
2926 let branch = head
2927 .shorthand()
2928 .map_err(|error| git_error(format!("Git branch name is not valid UTF-8: {error}")))?;
2929 let desired_view = repo
2930 .desired_view_name(working_copy)
2931 .map_err(CliError::from)?;
2932 if branch != desired_view {
2933 return Err(git_error(format!(
2934 "Git branch '{branch}' does not match current Atomic view '{desired_view}'"
2935 )));
2936 }
2937
2938 let atomic_status = repo
2939 .status(working_copy, StatusOptions::default())
2940 .map_err(CliError::from)?;
2941 if !atomic_status.is_clean() {
2942 return Err(git_error("Atomic working copy is not clean"));
2943 }
2944 require_clean_git_index(git)?;
2945
2946 // Build and verify the complete graph-derived projection before creating
2947 // any Git object, commit, ref, or index mutation. The Git index may still
2948 // describe the old HEAD on an Atomic→Git reconcile, so only the worktree
2949 // layer is applicable until the new tree is published.
2950 let policy = conversion_policy(git)?;
2951 let project = repo
2952 .project_tree(&desired_view, &policy)
2953 .map_err(|error| git_error(format!("cannot build complete Atomic projection: {error}")))?;
2954 let index = observe_git_index(root, &policy)
2955 .map_err(|error| git_error(format!("cannot observe Git index: {error}")))?;
2956 let filter = GitAttributesFilter::for_repository(root);
2957 let worktree = observe_worktree(root, Some(&index), &filter, &policy)
2958 .map_err(|error| git_error(format!("cannot observe Git worktree: {error}")))?;
2959 let report = compare_project_to_worktree_with_index(&project, &worktree, &index, &policy);
2960 if !report.is_equivalent() {
2961 return Err(equivalence_error("Atomic-to-Git shim projection", &report));
2962 }
2963 let tree_oid = write_project_tree(git, &project)?;
2964 let tree = git
2965 .find_tree(tree_oid)
2966 .map_err(|error| git_error(format!("cannot read projected Git tree: {error}")))?;
2967 let parent = head
2968 .peel_to_commit()
2969 .map_err(|error| git_error(format!("cannot read Git HEAD commit: {error}")))?;
2970 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