From e136d05789b08744cfe48772cfaf81f806a4cd6a Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 24 Aug 2024 20:58:35 +0800 Subject: [PATCH] enhance: using `-- ...` instead of `--pathspec-from-file=` (#404) --- src/Commands/Stash.cs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/Commands/Stash.cs b/src/Commands/Stash.cs index 3e784f60..cf7d84d1 100644 --- a/src/Commands/Stash.cs +++ b/src/Commands/Stash.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using System.IO; +using System.Text; namespace SourceGit.Commands { @@ -19,14 +19,11 @@ namespace SourceGit.Commands public bool Push(List changes, string message) { - var temp = Path.GetTempFileName(); - var stream = new FileStream(temp, FileMode.Create); - var writer = new StreamWriter(stream); - + var pathsBuilder = new StringBuilder(); var needAdd = new List(); foreach (var c in changes) { - writer.WriteLine(c.Path); + pathsBuilder.Append($"\"{c.Path}\" "); if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked) { @@ -44,15 +41,9 @@ namespace SourceGit.Commands needAdd.Clear(); } - writer.Flush(); - stream.Flush(); - writer.Close(); - stream.Close(); - - Args = $"stash push -m \"{message}\" --pathspec-from-file=\"{temp}\""; - var succ = Exec(); - File.Delete(temp); - return succ; + var paths = pathsBuilder.ToString(); + Args = $"stash push -m \"{message}\" -- {paths}"; + return Exec(); } public bool Apply(string name)