From 119b0fe95ce8d161202124ab5d43e2bce2cecfc7 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 20 May 2025 09:16:40 +0800 Subject: [PATCH] feature: log output of custom action if `Wait for action exit` enabled (#1334) Signed-off-by: leo --- src/Commands/ExecuteCustomAction.cs | 8 +++++--- src/ViewModels/ExecuteCustomAction.cs | 5 ++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Commands/ExecuteCustomAction.cs b/src/Commands/ExecuteCustomAction.cs index 000c8fd1..e59bc068 100644 --- a/src/Commands/ExecuteCustomAction.cs +++ b/src/Commands/ExecuteCustomAction.cs @@ -27,7 +27,7 @@ namespace SourceGit.Commands } } - public static void RunAndWait(string repo, string file, string args, Action outputHandler) + public static void RunAndWait(string repo, string file, string args, Models.ICommandLog log) { var start = new ProcessStartInfo(); start.FileName = file; @@ -40,20 +40,22 @@ namespace SourceGit.Commands 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) - outputHandler?.Invoke(e.Data); + log?.AppendLine(e.Data); }; proc.ErrorDataReceived += (_, e) => { if (e.Data != null) { - outputHandler?.Invoke(e.Data); + log?.AppendLine(e.Data); builder.AppendLine(e.Data); } }; diff --git a/src/ViewModels/ExecuteCustomAction.cs b/src/ViewModels/ExecuteCustomAction.cs index 52729e56..30345d99 100644 --- a/src/ViewModels/ExecuteCustomAction.cs +++ b/src/ViewModels/ExecuteCustomAction.cs @@ -36,13 +36,16 @@ namespace SourceGit.ViewModels _repo.SetWatcherEnabled(false); ProgressDescription = "Run custom action ..."; + var log = _repo.CreateLog(CustomAction.Name); + return Task.Run(() => { if (CustomAction.WaitForExit) - Commands.ExecuteCustomAction.RunAndWait(_repo.FullPath, CustomAction.Executable, _args, output => CallUIThread(() => ProgressDescription = output)); + Commands.ExecuteCustomAction.RunAndWait(_repo.FullPath, CustomAction.Executable, _args, log); else Commands.ExecuteCustomAction.Run(_repo.FullPath, CustomAction.Executable, _args); + log.Complete(); CallUIThread(() => _repo.SetWatcherEnabled(true)); return true; });