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

Method run

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

Source from the content-addressed store, hash-verified

74
75impl Command for Push {
76 fn run(&self) -> CliResult<()> {
77 // Find and open the Atomic repository
78 let repo_root = find_repository_root()?;
79 let repo = Repository::open(&repo_root).map_err(CliError::Repository)?;
80
81 // Open the Git repository
82 let git_repo = GitRepository::discover(&repo_root).map_err(|_| CliError::GitError {
83 message: "Not a git repository (or any parent up to mount point)".to_string(),
84 })?;
85
86 // Get current view name for trailers
87 let current_view = repo.current_view().to_string();
88
89 // Resolve the git branch this push targets. Explicit `--branch` wins;
90 // otherwise a draft view maps to a git branch named after the view so
91 // each draft publishes to its own remote ref. Shared views keep the
92 // historical behavior (commit lands on the current git branch).
93 let view_scope = repo
94 .get_view_info(&current_view)
95 .map_err(CliError::Repository)?
96 .scope;
97 let branch_override =
98 Self::resolve_branch_override(self.branch.as_deref(), view_scope, &current_view)?;
99 if self.branch.is_none() {
100 if let Some(ref branch) = branch_override {
101 print_info(&format!(
102 "Draft view '{}' publishes to git branch '{}' (created on the remote if absent).",
103 current_view, branch
104 ));
105 }
106 }
107 let target_override = branch_override.as_deref();
108
109 // Load change history for commit message + trailers
110 let history = repo
111 .log(HistoryOptions::default().load_headers(true))
112 .map_err(CliError::Repository)?;
113
114 if history.is_empty() {
115 print_info("No changes recorded in the current view. Nothing to push.");
116 return Ok(());
117 }
118
119 // Determine which changes are new since the last `atomic git push`.
120 // We walk git history to find the most recent commit whose
121 // Atomic-View trailer matches the current view, then use its
122 // Atomic-State to locate our position in the view's history.
123 let last_pushed_state = self.find_last_pushed_state(&git_repo, &current_view);
124 let start_idx = match &last_pushed_state {
125 Some(state) => history
126 .iter()
127 .position(|e| &e.state == state)
128 .map(|i| i + 1)
129 .unwrap_or(0),
130 None => 0,
131 };
132 let new_history = &history[start_idx..];
133 let new_count = new_history.len();

Callers

nothing calls this directly

Calls 15

find_repository_rootFunction · 0.85
print_infoFunction · 0.85
print_successFunction · 0.85
print_warningFunction · 0.85
current_viewMethod · 0.80
get_view_infoMethod · 0.80
is_noneMethod · 0.80
logMethod · 0.80
load_headersMethod · 0.80
unpushed_commit_countMethod · 0.80
push_to_remoteMethod · 0.80

Tested by

no test coverage detected