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

Method run

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

Source from the content-addressed store, hash-verified

60
61impl Command for Push {
62 fn run(&self) -> CliResult<()> {
63 // Find and open the Atomic repository
64 let repo_root = find_repository_root()?;
65 let repo = Repository::open(&repo_root).map_err(CliError::Repository)?;
66
67 // Open the Git repository
68 let git_repo = GitRepository::discover(&repo_root).map_err(|_| CliError::GitError {
69 message: "Not a git repository (or any parent up to mount point)".to_string(),
70 })?;
71
72 // Get current view name for trailers
73 let current_view = repo.current_view().to_string();
74
75 // Load change history for commit message + trailers
76 let history = repo
77 .log(HistoryOptions::default().load_headers(true))
78 .map_err(CliError::Repository)?;
79
80 if history.is_empty() {
81 print_info("No changes recorded in the current view. Nothing to push.");
82 return Ok(());
83 }
84
85 // Stage everything: git add -A (add_all + update_all handles new files and deletions)
86 let mut index = git_repo.index().map_err(|e| CliError::GitError {
87 message: format!("Failed to open git index: {}", e),
88 })?;
89 index
90 .add_all(["*"].iter(), git2::IndexAddOption::DEFAULT, None)
91 .map_err(|e| CliError::GitError {
92 message: format!("Failed to stage files: {}", e),
93 })?;
94 index
95 .update_all(["*"].iter(), None)
96 .map_err(|e| CliError::GitError {
97 message: format!("Failed to update index: {}", e),
98 })?;
99 index.write().map_err(|e| CliError::GitError {
100 message: format!("Failed to write index: {}", e),
101 })?;
102
103 let tree_oid = index.write_tree().map_err(|e| CliError::GitError {
104 message: format!("Failed to write tree: {}", e),
105 })?;
106 let tree = git_repo
107 .find_tree(tree_oid)
108 .map_err(|e| CliError::GitError {
109 message: format!("Failed to find tree: {}", e),
110 })?;
111
112 // Check if tree differs from HEAD — skip commit if nothing changed
113 let head_tree = git_repo
114 .head()
115 .ok()
116 .and_then(|h| h.peel_to_commit().ok())
117 .and_then(|c| c.tree().ok());
118
119 if let Some(ref ht) = head_tree {

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
build_commit_messageMethod · 0.80
as_refMethod · 0.80
commitMethod · 0.80
push_to_remoteMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected