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,
)
| 1406 | /// already holds that tree (staged content is never overwritten by an |
| 1407 | /// adoption). Anything else returns `None`. |
| 1408 | fn 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 | /// |
no test coverage detected