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

Method run

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

Source from the content-addressed store, hash-verified

68
69impl Command for Push {
70 fn run(&self) -> CliResult<()> {
71 // Find and open the Atomic repository
72 let repo_root = find_repository_root()?;
73 let repo = Repository::open(&repo_root).map_err(CliError::Repository)?;
74
75 // Open the Git repository
76 let git_repo = GitRepository::discover(&repo_root).map_err(|_| CliError::GitError {
77 message: "Not a git repository (or any parent up to mount point)".to_string(),
78 })?;
79
80 // Get current view name for trailers
81 let current_view = repo.current_view().to_string();
82
83 // Load change history for commit message + trailers
84 let history = repo
85 .log(HistoryOptions::default().load_headers(true))
86 .map_err(CliError::Repository)?;
87
88 if history.is_empty() {
89 print_info("No changes recorded in the current view. Nothing to push.");
90 return Ok(());
91 }
92
93 // Determine which changes are new since the last `atomic git push`.
94 // We walk git history to find the most recent commit whose
95 // Atomic-View trailer matches the current view, then use its
96 // Atomic-State to locate our position in the view's history.
97 let last_pushed_state = self.find_last_pushed_state(&git_repo, &current_view);
98 let start_idx = match &last_pushed_state {
99 Some(state) => history
100 .iter()
101 .position(|e| &e.state == state)
102 .map(|i| i + 1)
103 .unwrap_or(0),
104 None => 0,
105 };
106 let new_history = &history[start_idx..];
107 let new_count = new_history.len();
108
109 // Stage everything: git add -A (add_all + update_all handles new files and deletions)
110 let mut index = git_repo.index().map_err(|e| CliError::GitError {
111 message: format!("Failed to open git index: {}", e),
112 })?;
113 index
114 .add_all(["*"].iter(), git2::IndexAddOption::DEFAULT, None)
115 .map_err(|e| CliError::GitError {
116 message: format!("Failed to stage files: {}", e),
117 })?;
118 index
119 .update_all(["*"].iter(), None)
120 .map_err(|e| CliError::GitError {
121 message: format!("Failed to update index: {}", e),
122 })?;
123 index.write().map_err(|e| CliError::GitError {
124 message: format!("Failed to write index: {}", e),
125 })?;
126
127 let tree_oid = index.write_tree().map_err(|e| CliError::GitError {

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
logMethod · 0.80
load_headersMethod · 0.80
unpushed_commit_countMethod · 0.80
is_noneMethod · 0.80
push_to_remoteMethod · 0.80
lastMethod · 0.80

Tested by

no test coverage detected