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:1768–1814  ·  view source on GitHub ↗
(
    git: &GitRepository,
    target: &str,
    target_tree_oid: Oid,
    atomic_state: &str,
)

Source from the content-addressed store, hash-verified

1766}
1767
1768fn find_or_create_target_commit(
1769 git: &GitRepository,
1770 target: &str,
1771 target_tree_oid: Oid,
1772 atomic_state: &str,
1773) -> CliResult<Oid> {
1774 let target_ref = format!("refs/heads/{target}");
1775 let parent_oid = match git.find_reference(&target_ref) {
1776 Ok(reference) => {
1777 let commit = reference.peel_to_commit().map_err(|error| {
1778 git_error(format!("cannot read target branch '{target}': {error}"))
1779 })?;
1780 if commit.tree_id() == target_tree_oid {
1781 return Ok(commit.id());
1782 }
1783 // Append to the target branch so updating it is a fast-forward;
1784 // never parent from another branch and force-move target history.
1785 commit.id()
1786 }
1787 Err(error) if error.code() == git2::ErrorCode::NotFound => git
1788 .head()
1789 .and_then(|head| head.peel_to_commit())
1790 .map_err(|error| git_error(format!("cannot read current Git HEAD commit: {error}")))?
1791 .id(),
1792 Err(error) => {
1793 return Err(git_error(format!(
1794 "cannot inspect target branch '{target}': {error}"
1795 )))
1796 }
1797 };
1798 let parent = git
1799 .find_commit(parent_oid)
1800 .map_err(|error| git_error(format!("cannot read target parent commit: {error}")))?;
1801 let tree = git
1802 .find_tree(target_tree_oid)
1803 .map_err(|error| git_error(format!("cannot read target Git tree: {error}")))?;
1804 let signature = projection_signature(git)?;
1805 let message = format!(
1806 "Atomic shim switch projection\n\nAtomic-View: {target}\nAtomic-State: {atomic_state}\n"
1807 );
1808 git.commit(None, &signature, &signature, &message, &tree, &[&parent])
1809 .map_err(|error| {
1810 git_error(format!(
1811 "cannot create target compatibility commit: {error}"
1812 ))
1813 })
1814}
1815
1816fn update_target_branch(
1817 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