getGitLastRemoteCommitHash function

Future<String> getGitLastRemoteCommitHash(
  1. String root
)

获取代码的远程分支的最新哈希

Implementation

Future<String> getGitLastRemoteCommitHash(String root) async {
  final localCurrentBranch = await getLocalBranchName(root);

  /// 更新远程仓库
  await runCommand(root, '''
git reset --hard
git fetch origin
''');
  final remoteCommitHashCode = await runCommand(
    root,
    'git ls-remote --heads origin $localCurrentBranch | awk \'{print \$1}\'',
  ).then((value) {
    /// bb2b2fb44d073c7cbea05e11c905543072b10b63	refs/heads/ArtStyle_1.0
    final reg = RegExp('[0-9+a-z]*');
    return reg.firstMatch(value.first.stdout.toString())!.group(0);
  });
  return remoteCommitHashCode!.trim();
}