From 892f3b80328f5bfeb470a93c4857855565d3a1fb Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 18 Apr 2025 10:24:20 +0800 Subject: [PATCH] code_style: move `SourceGit.CommandExtensions` to `SourceGit.ViewModels.CommandExtensions` Signed-off-by: leo --- src/App.Utils.cs | 11 ----------- src/Commands/Branch.cs | 2 +- src/Commands/Discard.cs | 8 ++++---- src/ViewModels/CommandLog.cs | 9 +++++++++ 4 files changed, 14 insertions(+), 16 deletions(-) delete mode 100644 src/App.Utils.cs diff --git a/src/App.Utils.cs b/src/App.Utils.cs deleted file mode 100644 index 4fc91a5b..00000000 --- a/src/App.Utils.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace SourceGit -{ - public static class CommandExtensions - { - public static T Use(this T cmd, Models.ICommandLog log) where T : Commands.Command - { - cmd.Log = log; - return cmd; - } - } -} diff --git a/src/Commands/Branch.cs b/src/Commands/Branch.cs index 72dadc17..9c396215 100644 --- a/src/Commands/Branch.cs +++ b/src/Commands/Branch.cs @@ -60,7 +60,7 @@ { bool exists = new Remote(repo).HasBranch(remote, name); if (exists) - return new Push(repo, remote, $"refs/heads/{name}", true).Use(log).Exec(); + return new Push(repo, remote, $"refs/heads/{name}", true) { Log = log }.Exec(); var cmd = new Command(); cmd.WorkingDirectory = repo; diff --git a/src/Commands/Discard.cs b/src/Commands/Discard.cs index cd7858a6..f837df52 100644 --- a/src/Commands/Discard.cs +++ b/src/Commands/Discard.cs @@ -7,8 +7,8 @@ namespace SourceGit.Commands { public static void All(string repo, bool includeIgnored, Models.ICommandLog log) { - new Restore(repo).Use(log).Exec(); - new Clean(repo, includeIgnored).Use(log).Exec(); + new Restore(repo) { Log = log }.Exec(); + new Clean(repo, includeIgnored) { Log = log }.Exec(); } public static void Changes(string repo, List changes, Models.ICommandLog log) @@ -27,13 +27,13 @@ namespace SourceGit.Commands for (int i = 0; i < needClean.Count; i += 10) { var count = Math.Min(10, needClean.Count - i); - new Clean(repo, needClean.GetRange(i, count)).Use(log).Exec(); + new Clean(repo, needClean.GetRange(i, count)) { Log = log }.Exec(); } for (int i = 0; i < needCheckout.Count; i += 10) { var count = Math.Min(10, needCheckout.Count - i); - new Restore(repo, needCheckout.GetRange(i, count), "--worktree --recurse-submodules").Use(log).Exec(); + new Restore(repo, needCheckout.GetRange(i, count), "--worktree --recurse-submodules") { Log = log }.Exec(); } } } diff --git a/src/ViewModels/CommandLog.cs b/src/ViewModels/CommandLog.cs index a677d0be..4286b93f 100644 --- a/src/ViewModels/CommandLog.cs +++ b/src/ViewModels/CommandLog.cs @@ -84,4 +84,13 @@ namespace SourceGit.ViewModels private StringBuilder _builder = new StringBuilder(); private event Action _onNewLineReceived; } + + public static class CommandExtensions + { + public static T Use(this T cmd, CommandLog log) where T : Commands.Command + { + cmd.Log = log; + return cmd; + } + } }