mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-25 21:07:20 -08:00
refactor: rewrite command git stash push
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
a7cccd5c1d
commit
1418591b0b
1 changed files with 12 additions and 11 deletions
|
@ -19,24 +19,27 @@ namespace SourceGit.Commands
|
||||||
|
|
||||||
public bool Push(List<Models.Change> changes, string message, bool onlyStaged, bool keepIndex)
|
public bool Push(List<Models.Change> changes, string message, bool onlyStaged, bool keepIndex)
|
||||||
{
|
{
|
||||||
var pathsBuilder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
|
builder.Append("stash push ");
|
||||||
var indexOpts = keepIndex ? "--keep-index" : "";
|
if (onlyStaged)
|
||||||
|
builder.Append("--staged ");
|
||||||
|
if (keepIndex)
|
||||||
|
builder.Append("--keep-index ");
|
||||||
|
builder.Append("-m \"");
|
||||||
|
builder.Append(message);
|
||||||
|
builder.Append("\" -- ");
|
||||||
|
|
||||||
if (onlyStaged)
|
if (onlyStaged)
|
||||||
{
|
{
|
||||||
foreach (var c in changes)
|
foreach (var c in changes)
|
||||||
pathsBuilder.Append($"\"{c.Path}\" ");
|
builder.Append($"\"{c.Path}\" ");
|
||||||
|
|
||||||
var paths = pathsBuilder.ToString();
|
|
||||||
Args = $"stash push {indexOpts} --staged -m \"{message}\" -- {paths}";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var needAdd = new List<Models.Change>();
|
var needAdd = new List<Models.Change>();
|
||||||
foreach (var c in changes)
|
foreach (var c in changes)
|
||||||
{
|
{
|
||||||
pathsBuilder.Append($"\"{c.Path}\" ");
|
builder.Append($"\"{c.Path}\" ");
|
||||||
|
|
||||||
if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
|
if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
|
||||||
{
|
{
|
||||||
|
@ -53,11 +56,9 @@ namespace SourceGit.Commands
|
||||||
new Add(WorkingDirectory, needAdd).Exec();
|
new Add(WorkingDirectory, needAdd).Exec();
|
||||||
needAdd.Clear();
|
needAdd.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
var paths = pathsBuilder.ToString();
|
|
||||||
Args = $"stash push {indexOpts} -m \"{message}\" -- {paths}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Args = builder.ToString();
|
||||||
return Exec();
|
return Exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue