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

Function adoptable_managed_commit

atomic-cli/src/commands/git/shadow.rs:1408–1431  ·  view source on GitHub ↗

The commit to adopt as a Draft view's projection, if it qualifies. Adoption keeps the commit (message, author and all) as Git history and only moves Atomic's bookkeeping onto it, so every condition is checked against live Git state: HEAD is detached exactly at the commit, the commit is the single direct child of the view's current projection, its tree is byte-for-byte the verified projection of t

(
    git_repo: &'repo GitRepository,
    view_ref: &str,
    managed_commit: git2::Oid,
    projected_tree: git2::Oid,
)

Source from the content-addressed store, hash-verified

1406/// already holds that tree (staged content is never overwritten by an
1407/// adoption). Anything else returns `None`.
1408fn adoptable_managed_commit<'repo>(
1409 git_repo: &'repo GitRepository,
1410 view_ref: &str,
1411 managed_commit: git2::Oid,
1412 projected_tree: git2::Oid,
1413) -> Option<git2::Commit<'repo>> {
1414 if !git_repo.head_detached().unwrap_or(false) {
1415 return None;
1416 }
1417 if git_repo.head().ok()?.target()? != managed_commit {
1418 return None;
1419 }
1420 let commit = git_repo.find_commit(managed_commit).ok()?;
1421 let projection = git_repo.find_reference(view_ref).ok()?.target()?;
1422 if commit.parent_count() != 1 || commit.parent_id(0).ok()? != projection {
1423 return None;
1424 }
1425 if commit.tree_id() != projected_tree {
1426 return None;
1427 }
1428 let tree = commit.tree().ok()?;
1429 let staged = git_repo.diff_tree_to_index(Some(&tree), None, None).ok()?;
1430 (staged.deltas().len() == 0).then_some(commit)
1431}
1432
1433/// Finish an adoption that was recorded but not completed.
1434///

Callers 1

Calls 4

treeMethod · 0.80
okMethod · 0.45
headMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected