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

Method run

atomic-cli/src/commands/git/push.rs:85–320  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

83
84impl Command for Push {
85 fn run(&self) -> CliResult<()> {
86 // Find and open the Atomic repository
87 let repo_root = find_repository_root()?;
88 let repo = Repository::open(&repo_root).map_err(CliError::Repository)?;
89
90 // Open the Git repository
91 let git_repo = GitRepository::discover(&repo_root).map_err(|_| CliError::GitError {
92 message: "Not a git repository (or any parent up to mount point)".to_string(),
93 })?;
94
95 // Get current view name for trailers
96 let current_view = repo.current_view().to_string();
97
98 // Serialize the shadow-commit pipeline (SPEC §4.3): acquire the
99 // repo-scoped lock OUTERMOST, before any staging or git mutation. If
100 // another shadow materialize/commit is in flight this is a logged no-op
101 // — the in-flight operation owns this commit. Held for the whole run.
102 let _shadow_lock =
103 match super::shadow::acquire_shadow_lock(&repo, &repo_root, &current_view)? {
104 Some(guard) => guard,
105 None => return Ok(()),
106 };
107
108 // Resolve the git branch this push targets. Explicit `--branch` wins;
109 // otherwise a draft view maps to a git branch named after the view so
110 // each draft publishes to its own remote ref. Shared views keep the
111 // historical behavior (commit lands on the current git branch).
112 let view_scope = repo
113 .get_view_info(&current_view)
114 .map_err(CliError::Repository)?
115 .scope;
116 let branch_override =
117 Self::resolve_branch_override(self.branch.as_deref(), view_scope, &current_view)?;
118 if self.branch.is_none() {
119 if let Some(ref branch) = branch_override {
120 print_info(&format!(
121 "Draft view '{}' publishes to git branch '{}' (created on the remote if absent).",
122 current_view, branch
123 ));
124 }
125 }
126 let target_override = branch_override.as_deref();
127
128 // Load change history for commit message + trailers
129 let history = repo
130 .log(HistoryOptions::default().load_headers(true))
131 .map_err(CliError::Repository)?;
132
133 if history.is_empty() {
134 print_info("No changes recorded in the current view. Nothing to push.");
135 return Ok(());
136 }
137
138 // Determine which changes are new since the last `atomic git push`.
139 // We walk git history to find the most recent commit whose
140 // Atomic-View trailer matches the current view, then use its
141 // Atomic-State to locate our position in the view's history.
142 let last_pushed_state = self.find_last_pushed_state(&git_repo, &current_view);

Callers

nothing calls this directly

Calls 15

find_repository_rootFunction · 0.85
acquire_shadow_lockFunction · 0.85
print_infoFunction · 0.85
print_warningFunction · 0.85
stage_and_validate_treeFunction · 0.85
print_successFunction · 0.85
current_viewMethod · 0.80
get_view_infoMethod · 0.80
is_noneMethod · 0.80
logMethod · 0.80
load_headersMethod · 0.80

Tested by

no test coverage detected