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

Method push_to_remote

atomic-cli/src/commands/git/push.rs:737–980  ·  view source on GitHub ↗

Push the current branch to the remote. Delegates the network operation to the `git` CLI so authentication behaves exactly like a plain `git push`: OpenSSH client config (`Host`/`IdentityFile`/`IdentitiesOnly`), ssh-agents, askpass prompts, and HTTPS credential helpers all work as the user expects. Do not "simplify" this back to libgit2's transport: its credential callback can only consult the ss

(
        &self,
        repo: &Repository,
        repo_root: &std::path::Path,
        git_repo: &GitRepository,
        override_branch: Option<&str>,
        publication: &super::shadow::VerifiedP

Source from the content-addressed store, hash-verified

735 /// the new remote tip is verified after the push and recorded back into
736 /// the mapping, so the next push is leased against it.
737 fn push_to_remote(
738 &self,
739 repo: &Repository,
740 repo_root: &std::path::Path,
741 git_repo: &GitRepository,
742 override_branch: Option<&str>,
743 publication: &super::shadow::VerifiedPublication,
744 common: &atomic_repository::RepositoryCommonLockGuard,
745 ) -> CliResult<()> {
746 let head = git_repo.head().map_err(|e| CliError::GitError {
747 message: format!("Failed to get HEAD: {}", e),
748 })?;
749 let current = head.shorthand().unwrap_or("HEAD");
750 let target = override_branch.unwrap_or(current);
751 let destination = format!("refs/heads/{}", target);
752 if !super::is_publishable_git_ref(destination.as_bytes()) {
753 return Err(CliError::GitError {
754 message: format!("refusing to publish local recovery ref '{destination}'"),
755 });
756 }
757 // CB-10B review R3: push the PINNED verified commit, never the
758 // mutable HEAD — the refspec names the exact commit the publication
759 // snapshot verified, so a branch that moves after verification
760 // cannot change what is pushed.
761 let verified_head = publication.git_head.ok_or_else(|| CliError::GitError {
762 message: "the verified publication carries no Git commit to push".to_string(),
763 })?;
764 let refspec = format!("{}:{destination}", verified_head);
765
766 let workdir = git_repo.workdir().ok_or_else(|| CliError::GitError {
767 message: "Git repository has no working directory (bare repository?)".to_string(),
768 })?;
769
770 // Re-observe immediately before handing the ref effect to `git push`.
771 publication.reobserve_for_git_push(repo, repo_root, git_repo)?;
772
773 // CB-10B remote lease (RFC §8.5). Every mapped view push runs under
774 // an expected-old lease: the mapping's last_observed_remote pins the
775 // expected remote tip, an unobserved remote is observed explicitly
776 // first, and the verified new tip is recorded back for the next
777 // push. The working copy comes from the publication boundary.
778 let current_view = publication.view().to_string();
779 let working_copy = repo
780 .require_working_copy_id()
781 .map_err(CliError::Repository)?;
782 let mapping = match repo
783 .get_ref_mapping(&current_view)
784 .map_err(CliError::Repository)?
785 {
786 Some(mapping) => Some(mapping),
787 None => {
788 // First push for this view: create the baseline mapping so
789 // the remote observation below has a durable row to advance.
790 super::ref_mapping::ensure_baseline_mapping(
791 repo,
792 working_copy,
793 git_repo,
794 &current_view,

Callers 1

runMethod · 0.80

Calls 15

is_publishable_git_refFunction · 0.85
ensure_baseline_mappingFunction · 0.85
remote_lease_refspecFunction · 0.85
observe_remote_refFunction · 0.85
print_warningFunction · 0.85
get_ref_mappingMethod · 0.80
as_refMethod · 0.80
successMethod · 0.80
headMethod · 0.45

Tested by

no test coverage detected