pushToGit function

Future pushToGit()

Push Git

Implementation

Future pushToGit() async {
  try {
    if (!selectPushToGit()) return;
    printMessage('Git add\n');
    final processGitAdd = await Process.start('git', ['add', '.'], workingDirectory: projectPath, runInShell: true);
    processGitAdd.stdout.transform(utf8.decoder).listen((data) => printMessage(data));
    processGitAdd.stderr.transform(utf8.decoder).listen((data) => printErrorMessage(data));
    await processGitAdd.exitCode;

    printMessage('Git commit\n');
    final processGitCommit = await Process.start(
      'git',
      ['commit', '-m', 'chore: release v${VersionManage().version}'],
      workingDirectory: projectPath,
      runInShell: true,
    );
    processGitCommit.stdout.transform(utf8.decoder).listen((data) => printMessage(data));
    processGitCommit.stderr.transform(utf8.decoder).listen((data) => printErrorMessage(data));
    await processGitCommit.exitCode;
    await push();
  } catch (e) {
    printErrorMessage('推送至 Git 异常:$e');
  }
}