(&self)
| 68 | |
| 69 | impl 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, ¤t_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 { |
nothing calls this directly
no test coverage detected