2024-02-05 23:08:37 -08:00
|
|
|
|
using System.Collections.Generic;
|
2024-08-24 05:58:35 -07:00
|
|
|
|
using System.Text;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public class Stash : Command
|
|
|
|
|
{
|
|
|
|
|
public Stash(string repo)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
WorkingDirectory = repo;
|
|
|
|
|
Context = repo;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Push(string message)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = $"stash push -m \"{message}\"";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
2023-10-10 01:59:47 -07:00
|
|
|
|
|
2024-10-03 03:28:01 -07:00
|
|
|
|
public bool Push(List<Models.Change> changes, string message, bool onlyStaged)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-08-24 05:58:35 -07:00
|
|
|
|
var pathsBuilder = new StringBuilder();
|
2023-10-10 01:59:47 -07:00
|
|
|
|
|
2024-10-03 03:28:01 -07:00
|
|
|
|
if (onlyStaged)
|
|
|
|
|
{
|
|
|
|
|
foreach (var c in changes)
|
|
|
|
|
pathsBuilder.Append($"\"{c.Path}\" ");
|
2024-10-14 18:39:01 -07:00
|
|
|
|
|
2024-10-03 03:28:01 -07:00
|
|
|
|
var paths = pathsBuilder.ToString();
|
|
|
|
|
Args = $"stash push --staged -m \"{message}\" -- {paths}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var needAdd = new List<Models.Change>();
|
|
|
|
|
foreach (var c in changes)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-10-03 03:28:01 -07:00
|
|
|
|
pathsBuilder.Append($"\"{c.Path}\" ");
|
|
|
|
|
|
|
|
|
|
if (c.WorkTree == Models.ChangeState.Added || c.WorkTree == Models.ChangeState.Untracked)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-10-03 03:28:01 -07:00
|
|
|
|
needAdd.Add(c);
|
|
|
|
|
if (needAdd.Count > 10)
|
|
|
|
|
{
|
|
|
|
|
new Add(WorkingDirectory, needAdd).Exec();
|
|
|
|
|
needAdd.Clear();
|
|
|
|
|
}
|
2023-10-10 01:59:47 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-03 03:28:01 -07:00
|
|
|
|
if (needAdd.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
new Add(WorkingDirectory, needAdd).Exec();
|
|
|
|
|
needAdd.Clear();
|
|
|
|
|
}
|
2024-10-14 18:39:01 -07:00
|
|
|
|
|
2024-10-03 03:28:01 -07:00
|
|
|
|
var paths = pathsBuilder.ToString();
|
|
|
|
|
Args = $"stash push -m \"{message}\" -- {paths}";
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
2024-10-14 18:39:01 -07:00
|
|
|
|
|
2024-08-24 05:58:35 -07:00
|
|
|
|
return Exec();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Apply(string name)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"stash apply -q {name}";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Pop(string name)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"stash pop -q {name}";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Drop(string name)
|
|
|
|
|
{
|
2021-04-29 05:05:55 -07:00
|
|
|
|
Args = $"stash drop -q {name}";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
2024-02-05 23:08:37 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public bool Clear()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Args = "stash clear";
|
|
|
|
|
return Exec();
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|