Skip to content

Commit 1418591

Browse files
committed
refactor: rewrite command git stash push
Signed-off-by: leo <[email protected]>
1 parent a7cccd5 commit 1418591

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/Commands/Stash.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@ public bool Push(string message)
1919

2020
public bool Push(List<Models.Change> changes, string message, bool onlyStaged, bool keepIndex)
2121
{
22-
var pathsBuilder = new StringBuilder();
23-
24-
var indexOpts = keepIndex ? "--keep-index" : "";
22+
var builder = new StringBuilder();
23+
builder.Append("stash push ");
24+
if (onlyStaged)
25+
builder.Append("--staged ");
26+
if (keepIndex)
27+
builder.Append("--keep-index ");
28+
builder.Append("-m \"");
29+
builder.Append(message);
30+
builder.Append("\" -- ");
2531

2632
if (onlyStaged)
2733
{
2834
foreach (var c in changes)
29-
pathsBuilder.Append($"\"{c.Path}\" ");
30-
31-
var paths = pathsBuilder.ToString();
32-
Args = $"stash push {indexOpts} --staged -m \"{message}\" -- {paths}";
35+
builder.Append($"\"{c.Path}\" ");
3336
}
3437
else
3538
{
3639
var needAdd = new List<Models.Change>();
3740
foreach (var c in changes)
3841
{
39-
pathsBuilder.Append($"\"{c.Path}\" ");
42+
builder.Append($"\"{c.Path}\" ");
4043

4144
if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
4245
{
@@ -53,11 +56,9 @@ public bool Push(List<Models.Change> changes, string message, bool onlyStaged, b
5356
new Add(WorkingDirectory, needAdd).Exec();
5457
needAdd.Clear();
5558
}
56-
57-
var paths = pathsBuilder.ToString();
58-
Args = $"stash push {indexOpts} -m \"{message}\" -- {paths}";
5959
}
6060

61+
Args = builder.ToString();
6162
return Exec();
6263
}
6364

0 commit comments

Comments
 (0)