mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-26 21:04:59 +00:00
code_style: execute custom action has nothing to do with git command
Some checks are pending
Some checks are pending
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
83f1f2f6cd
commit
295718effe
2 changed files with 79 additions and 88 deletions
|
@ -1,86 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
using Avalonia.Threading;
|
|
||||||
|
|
||||||
namespace SourceGit.Commands
|
|
||||||
{
|
|
||||||
public static class ExecuteCustomAction
|
|
||||||
{
|
|
||||||
public static void Run(string repo, string file, string args)
|
|
||||||
{
|
|
||||||
var start = new ProcessStartInfo();
|
|
||||||
start.FileName = file;
|
|
||||||
start.Arguments = args;
|
|
||||||
start.UseShellExecute = false;
|
|
||||||
start.CreateNoWindow = true;
|
|
||||||
start.WorkingDirectory = repo;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Process.Start(start);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, e.Message));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void RunAndWait(string repo, string file, string args, Models.ICommandLog log)
|
|
||||||
{
|
|
||||||
var start = new ProcessStartInfo();
|
|
||||||
start.FileName = file;
|
|
||||||
start.Arguments = args;
|
|
||||||
start.UseShellExecute = false;
|
|
||||||
start.CreateNoWindow = true;
|
|
||||||
start.RedirectStandardOutput = true;
|
|
||||||
start.RedirectStandardError = true;
|
|
||||||
start.StandardOutputEncoding = Encoding.UTF8;
|
|
||||||
start.StandardErrorEncoding = Encoding.UTF8;
|
|
||||||
start.WorkingDirectory = repo;
|
|
||||||
|
|
||||||
log?.AppendLine($"$ {file} {args}\n");
|
|
||||||
|
|
||||||
var proc = new Process() { StartInfo = start };
|
|
||||||
var builder = new StringBuilder();
|
|
||||||
|
|
||||||
proc.OutputDataReceived += (_, e) =>
|
|
||||||
{
|
|
||||||
if (e.Data != null)
|
|
||||||
log?.AppendLine(e.Data);
|
|
||||||
};
|
|
||||||
|
|
||||||
proc.ErrorDataReceived += (_, e) =>
|
|
||||||
{
|
|
||||||
if (e.Data != null)
|
|
||||||
{
|
|
||||||
log?.AppendLine(e.Data);
|
|
||||||
builder.AppendLine(e.Data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
proc.Start();
|
|
||||||
proc.BeginOutputReadLine();
|
|
||||||
proc.BeginErrorReadLine();
|
|
||||||
proc.WaitForExit();
|
|
||||||
|
|
||||||
var exitCode = proc.ExitCode;
|
|
||||||
if (exitCode != 0)
|
|
||||||
{
|
|
||||||
var errMsg = builder.ToString().Trim();
|
|
||||||
if (!string.IsNullOrEmpty(errMsg))
|
|
||||||
Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, errMsg));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Dispatcher.UIThread.Invoke(() => App.RaiseException(repo, e.Message));
|
|
||||||
}
|
|
||||||
|
|
||||||
proc.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
@ -136,10 +138,12 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
return Task.Run(() =>
|
return Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
log.AppendLine($"$ {CustomAction.Executable} {cmdline}\n");
|
||||||
|
|
||||||
if (CustomAction.WaitForExit)
|
if (CustomAction.WaitForExit)
|
||||||
Commands.ExecuteCustomAction.RunAndWait(_repo.FullPath, CustomAction.Executable, cmdline, log);
|
RunAndWait(cmdline, log);
|
||||||
else
|
else
|
||||||
Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, cmdline);
|
Run(cmdline);
|
||||||
|
|
||||||
log.Complete();
|
log.Complete();
|
||||||
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
CallUIThread(() => _repo.SetWatcherEnabled(true));
|
||||||
|
@ -171,6 +175,79 @@ namespace SourceGit.ViewModels
|
||||||
return OperatingSystem.IsWindows() ? _repo.FullPath.Replace("/", "\\") : _repo.FullPath;
|
return OperatingSystem.IsWindows() ? _repo.FullPath.Replace("/", "\\") : _repo.FullPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Run(string args)
|
||||||
|
{
|
||||||
|
var start = new ProcessStartInfo();
|
||||||
|
start.FileName = CustomAction.Executable;
|
||||||
|
start.Arguments = args;
|
||||||
|
start.UseShellExecute = false;
|
||||||
|
start.CreateNoWindow = true;
|
||||||
|
start.WorkingDirectory = _repo.FullPath;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Process.Start(start);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
CallUIThread(() => App.RaiseException(_repo.FullPath, e.Message));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RunAndWait(string args, Models.ICommandLog log)
|
||||||
|
{
|
||||||
|
var start = new ProcessStartInfo();
|
||||||
|
start.FileName = CustomAction.Executable;
|
||||||
|
start.Arguments = args;
|
||||||
|
start.UseShellExecute = false;
|
||||||
|
start.CreateNoWindow = true;
|
||||||
|
start.RedirectStandardOutput = true;
|
||||||
|
start.RedirectStandardError = true;
|
||||||
|
start.StandardOutputEncoding = Encoding.UTF8;
|
||||||
|
start.StandardErrorEncoding = Encoding.UTF8;
|
||||||
|
start.WorkingDirectory = _repo.FullPath;
|
||||||
|
|
||||||
|
var proc = new Process() { StartInfo = start };
|
||||||
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
|
proc.OutputDataReceived += (_, e) =>
|
||||||
|
{
|
||||||
|
if (e.Data != null)
|
||||||
|
log?.AppendLine(e.Data);
|
||||||
|
};
|
||||||
|
|
||||||
|
proc.ErrorDataReceived += (_, e) =>
|
||||||
|
{
|
||||||
|
if (e.Data != null)
|
||||||
|
{
|
||||||
|
log?.AppendLine(e.Data);
|
||||||
|
builder.AppendLine(e.Data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
proc.Start();
|
||||||
|
proc.BeginOutputReadLine();
|
||||||
|
proc.BeginErrorReadLine();
|
||||||
|
proc.WaitForExit();
|
||||||
|
|
||||||
|
var exitCode = proc.ExitCode;
|
||||||
|
if (exitCode != 0)
|
||||||
|
{
|
||||||
|
var errMsg = builder.ToString().Trim();
|
||||||
|
if (!string.IsNullOrEmpty(errMsg))
|
||||||
|
CallUIThread(() => App.RaiseException(_repo.FullPath, errMsg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
CallUIThread(() => App.RaiseException(_repo.FullPath, e.Message));
|
||||||
|
}
|
||||||
|
|
||||||
|
proc.Close();
|
||||||
|
}
|
||||||
|
|
||||||
private readonly Repository _repo = null;
|
private readonly Repository _repo = null;
|
||||||
private readonly string _commandline = string.Empty;
|
private readonly string _commandline = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue