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 `--branch` overrides the target. Returns 0 when there is no remote ref to compare against.
(&self, git_repo: &GitRepository, branch_name: &str)
| 363 | /// or `refs/remotes/<remote>/<branch>` when `--branch` overrides the |
| 364 | /// target. Returns 0 when there is no remote ref to compare against. |
| 365 | fn unpushed_commit_count(&self, git_repo: &GitRepository, branch_name: &str) -> usize { |
| 366 | let local_ref = format!("refs/heads/{}", branch_name); |
| 367 | |
| 368 | let upstream_oid = match &self.branch { |
| 369 | // Explicit target: compare against the remote-tracking ref. |
| 370 | Some(target) => git_repo |
| 371 | .refname_to_id(&format!("refs/remotes/{}/{}", self.remote, target)) |
| 372 | .ok(), |
| 373 | // branch_upstream_name returns the full upstream refname |
| 374 | // (e.g. "refs/remotes/origin/main"), which resolves directly. |
| 375 | None => git_repo |
| 376 | .branch_upstream_name(&local_ref) |
| 377 | .ok() |
| 378 | .and_then(|buf| buf.as_str().map(str::to_owned)) |
| 379 | .and_then(|name| git_repo.refname_to_id(&name).ok()), |
| 380 | }; |
| 381 | |
| 382 | let local_oid = git_repo.refname_to_id(&local_ref).ok(); |
| 383 | |
| 384 | match (local_oid, upstream_oid) { |
| 385 | (Some(local), Some(upstream)) => git_repo |
| 386 | .graph_ahead_behind(local, upstream) |
| 387 | .map(|(ahead, _)| ahead) |
| 388 | .unwrap_or(0), |
| 389 | _ => 0, |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | /// Push the current branch to the remote. |
| 394 | /// |