代码

  1. private void GitUpdate()
  2. {
  3. // 设置Git命令和参数
  4. string gitCommand = "git";
  5. string gitArguments = "pull";
  6. string workingDirectory = UGFExtendEditorToolConfig.Data.DataTable_XlsxPath; // 替换为你的Git仓库路径
  7. if (!Directory.Exists(workingDirectory))
  8. {
  9. EditorUtility.DisplayDialog("更新失败", $"{workingDirectory} 不存在", "确定");
  10. return;
  11. }
  12. // 创建一个新的进程启动信息
  13. ProcessStartInfo startInfo = new ProcessStartInfo
  14. {
  15. FileName = gitCommand,
  16. Arguments = gitArguments,
  17. RedirectStandardOutput = true,
  18. RedirectStandardError = true,
  19. UseShellExecute = false,
  20. CreateNoWindow = true,
  21. WorkingDirectory = workingDirectory // 设置工作目录
  22. };
  23. // 启动进程并等待完成
  24. using (Process process = new Process { StartInfo = startInfo })
  25. {
  26. process.Start();
  27. // 读取标准输出和错误输出
  28. string output = process.StandardOutput.ReadToEnd();
  29. string error = process.StandardError.ReadToEnd();
  30. process.WaitForExit();
  31. if (string.IsNullOrEmpty(error))
  32. {
  33. if (EditorUtility.DisplayDialog("更新成功", output, "确定"))
  34. {
  35. RefreshFiles();
  36. }
  37. }
  38. else
  39. {
  40. EditorUtility.DisplayDialog("更新失败", error, "确定");
  41. }
  42. }
  43. }

参考

  1. ProcessStartInfo 类 (System.Diagnostics)
  2. Process 类 (System.Diagnostics)