From 1418591b0bf8af078f2a9ffa0eb25ac11bfd0847 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 28 Oct 2024 16:58:38 +0800 Subject: [PATCH] refactor: rewrite command `git stash push` Signed-off-by: leo --- src/Commands/Stash.cs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Commands/Stash.cs b/src/Commands/Stash.cs index 8554adde..77f1af53 100644 --- a/src/Commands/Stash.cs +++ b/src/Commands/Stash.cs @@ -19,24 +19,27 @@ namespace SourceGit.Commands public bool Push(List changes, string message, bool onlyStaged, bool keepIndex) { - var pathsBuilder = new StringBuilder(); - - var indexOpts = keepIndex ? "--keep-index" : ""; + var builder = new StringBuilder(); + builder.Append("stash push "); + if (onlyStaged) + builder.Append("--staged "); + if (keepIndex) + builder.Append("--keep-index "); + builder.Append("-m \""); + builder.Append(message); + builder.Append("\" -- "); if (onlyStaged) { foreach (var c in changes) - pathsBuilder.Append($"\"{c.Path}\" "); - - var paths = pathsBuilder.ToString(); - Args = $"stash push {indexOpts} --staged -m \"{message}\" -- {paths}"; + builder.Append($"\"{c.Path}\" "); } else { var needAdd = new List(); foreach (var c in changes) { - pathsBuilder.Append($"\"{c.Path}\" "); + builder.Append($"\"{c.Path}\" "); if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked) { @@ -53,11 +56,9 @@ namespace SourceGit.Commands new Add(WorkingDirectory, needAdd).Exec(); needAdd.Clear(); } - - var paths = pathsBuilder.ToString(); - Args = $"stash push {indexOpts} -m \"{message}\" -- {paths}"; } + Args = builder.ToString(); return Exec(); }