refactor: rewrite command git stash push

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2024-10-28 16:58:38 +08:00
parent a7cccd5c1d
commit 1418591b0b
No known key found for this signature in database

View file

@ -19,24 +19,27 @@ namespace SourceGit.Commands
public bool Push(List<Models.Change> 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<Models.Change>();
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();
}