(&self)
| 74 | |
| 75 | impl 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(¤t_view) |
| 95 | .map_err(CliError::Repository)? |
| 96 | .scope; |
| 97 | let branch_override = |
| 98 | Self::resolve_branch_override(self.branch.as_deref(), view_scope, ¤t_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, ¤t_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(); |
nothing calls this directly
no test coverage detected