checkHasBranch static method

Future<bool> checkHasBranch(
  1. String pathRep,
  2. String branch, {
  3. bool onlyRemote = true,
})

判断是否有当前指定分支

pathRep 仓库 branch 分支 onlyRemote 仅使用远程分支

Implementation

static Future<bool> checkHasBranch(
  String pathRep,
  String branch, {
  bool onlyRemote = true,
}) async {
  final branchSet = <String>{};
  {
    // remote branches
    final branches = await getRemoteBranchList(pathRep);
    branchSet.addAll(
      branches,
    );
  }

  if (!onlyRemote) {
    // local branches
    const cmdBranchLocal = 'git branch --format "%(refname:lstrip=2)"';
    final result = await ProcessUtil.runCmdWait(
      cmd: cmdBranchLocal,
      workingDirectory: pathRep,
    );
    if (result.stdout is String) {
      branchSet.addAll(
        parseBranchesInString(result.stdout as String),
      );
    }
  }

  Logger.log(
    'checkHasBranch.branchSet: $branchSet',
    'branch: $branch',
    'contains: ${branchSet.contains(branch)}',
  );
  return branchSet.where((s) {
    return s == branch;
  }).isNotEmpty;
}