Count commits on `branch_name` that haven't been pushed to the push target. The comparison point is the branch's configured upstream, or `refs/remotes/ / ` when a resolved target (explicit `--branch` or a draft view's mapped branch) redirects the push. Returns 0 when there is no remote ref to compare against.
(
&self,
git_repo: &GitRepository,
branch_name: &str,
override_branch: Option<&str>,
)
| 682 | /// (explicit `--branch` or a draft view's mapped branch) redirects the |
| 683 | /// push. Returns 0 when there is no remote ref to compare against. |
| 684 | fn unpushed_commit_count( |
| 685 | &self, |
| 686 | git_repo: &GitRepository, |
| 687 | branch_name: &str, |
| 688 | override_branch: Option<&str>, |
| 689 | ) -> usize { |
| 690 | let local_ref = format!("refs/heads/{}", branch_name); |
| 691 | |
| 692 | let upstream_oid = match override_branch { |
| 693 | // Redirected target: compare against the remote-tracking ref. |
| 694 | Some(target) => git_repo |
| 695 | .refname_to_id(&format!("refs/remotes/{}/{}", self.remote, target)) |
| 696 | .ok(), |
| 697 | // branch_upstream_name returns the full upstream refname |
| 698 | // (e.g. "refs/remotes/origin/main"), which resolves directly. |
| 699 | None => git_repo |
| 700 | .branch_upstream_name(&local_ref) |
| 701 | .ok() |
| 702 | .and_then(|buf| buf.as_str().ok().map(str::to_owned)) |
| 703 | .and_then(|name| git_repo.refname_to_id(&name).ok()), |
| 704 | }; |
| 705 | |
| 706 | let local_oid = git_repo.refname_to_id(&local_ref).ok(); |
| 707 | |
| 708 | match (local_oid, upstream_oid) { |
| 709 | (Some(local), Some(upstream)) => git_repo |
| 710 | .graph_ahead_behind(local, upstream) |
| 711 | .map(|(ahead, _)| ahead) |
| 712 | .unwrap_or(0), |
| 713 | _ => 0, |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | /// Push the current branch to the remote. |
| 718 | /// |