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

Method unpushed_commit_count

atomic-cli/src/commands/git/push.rs:429–460  ·  view source on GitHub ↗

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>,
    )

Source from the content-addressed store, hash-verified

427 /// (explicit `--branch` or a draft view's mapped branch) redirects the
428 /// push. Returns 0 when there is no remote ref to compare against.
429 fn unpushed_commit_count(
430 &self,
431 git_repo: &GitRepository,
432 branch_name: &str,
433 override_branch: Option<&str>,
434 ) -> usize {
435 let local_ref = format!("refs/heads/{}", branch_name);
436
437 let upstream_oid = match override_branch {
438 // Redirected target: compare against the remote-tracking ref.
439 Some(target) => git_repo
440 .refname_to_id(&format!("refs/remotes/{}/{}", self.remote, target))
441 .ok(),
442 // branch_upstream_name returns the full upstream refname
443 // (e.g. "refs/remotes/origin/main"), which resolves directly.
444 None => git_repo
445 .branch_upstream_name(&local_ref)
446 .ok()
447 .and_then(|buf| buf.as_str().map(str::to_owned))
448 .and_then(|name| git_repo.refname_to_id(&name).ok()),
449 };
450
451 let local_oid = git_repo.refname_to_id(&local_ref).ok();
452
453 match (local_oid, upstream_oid) {
454 (Some(local), Some(upstream)) => git_repo
455 .graph_ahead_behind(local, upstream)
456 .map(|(ahead, _)| ahead)
457 .unwrap_or(0),
458 _ => 0,
459 }
460 }
461
462 /// Push the current branch to the remote.
463 ///

Callers 1

runMethod · 0.80

Calls 1

as_strMethod · 0.45

Tested by

no test coverage detected