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

Function find_or_create_target_commit

atomic-cli/src/commands/git/shim.rs:1724–1770  ·  view source on GitHub ↗
(
    git: &GitRepository,
    target: &str,
    target_tree_oid: Oid,
    atomic_state: &str,
)

Source from the content-addressed store, hash-verified

1722}
1723
1724fn find_or_create_target_commit(
1725 git: &GitRepository,
1726 target: &str,
1727 target_tree_oid: Oid,
1728 atomic_state: &str,
1729) -> CliResult<Oid> {
1730 let target_ref = format!("refs/heads/{target}");
1731 let parent_oid = match git.find_reference(&target_ref) {
1732 Ok(reference) => {
1733 let commit = reference.peel_to_commit().map_err(|error| {
1734 git_error(format!("cannot read target branch '{target}': {error}"))
1735 })?;
1736 if commit.tree_id() == target_tree_oid {
1737 return Ok(commit.id());
1738 }
1739 // Append to the target branch so updating it is a fast-forward;
1740 // never parent from another branch and force-move target history.
1741 commit.id()
1742 }
1743 Err(error) if error.code() == git2::ErrorCode::NotFound => git
1744 .head()
1745 .and_then(|head| head.peel_to_commit())
1746 .map_err(|error| git_error(format!("cannot read current Git HEAD commit: {error}")))?
1747 .id(),
1748 Err(error) => {
1749 return Err(git_error(format!(
1750 "cannot inspect target branch '{target}': {error}"
1751 )))
1752 }
1753 };
1754 let parent = git
1755 .find_commit(parent_oid)
1756 .map_err(|error| git_error(format!("cannot read target parent commit: {error}")))?;
1757 let tree = git
1758 .find_tree(target_tree_oid)
1759 .map_err(|error| git_error(format!("cannot read target Git tree: {error}")))?;
1760 let signature = projection_signature(git)?;
1761 let message = format!(
1762 "Atomic shim switch projection\n\nAtomic-View: {target}\nAtomic-State: {atomic_state}\n"
1763 );
1764 git.commit(None, &signature, &signature, &message, &tree, &[&parent])
1765 .map_err(|error| {
1766 git_error(format!(
1767 "cannot create target compatibility commit: {error}"
1768 ))
1769 })
1770}
1771
1772fn update_target_branch(
1773 repo: &Repository,

Callers 1

switch_transactionFunction · 0.85

Calls 6

projection_signatureFunction · 0.85
git_errorFunction · 0.70
idMethod · 0.45
codeMethod · 0.45
headMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected