numChangesToPush method

Future<int?> numChangesToPush()

Implementation

Future<int?> numChangesToPush() async {
  var head = await (this.head() as FutureOr<Reference>);
  if (head.isHash || head.target == null) {
    return null;
  }

  var brConfig = config.branch(head.target!.branchName()!);
  var brConfigMerge = brConfig?.merge;
  var brConfigRemote = brConfig?.remote;
  if (brConfig == null || brConfigMerge == null || brConfigRemote == null) {
    return null;
  }

  // Construct remote's branch
  var remoteBranchName = brConfigMerge.branchName()!;
  var remoteRefName = ReferenceName.remote(brConfigRemote, remoteBranchName);

  var headRef = await resolveReference(head);
  var remoteRef = await resolveReferenceName(remoteRefName);
  if (headRef == null || remoteRef == null) {
    return null;
  }
  var headHash = headRef.hash;
  var remoteHash = headRef.hash;

  if (headHash == null || remoteHash == null) {
    return null;
  }
  if (headHash == remoteHash) {
    return 0;
  }

  var aheadBy = await countTillAncestor(headHash, remoteHash);
  return aheadBy != -1 ? aheadBy : 0;
}