2024-02-05 23:08:37 -08:00
|
|
|
|
using System;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
|
|
|
|
public static class Discard
|
|
|
|
|
{
|
|
|
|
|
public static void All(string repo)
|
|
|
|
|
{
|
2024-04-17 05:05:40 -07:00
|
|
|
|
new Restore(repo).Exec();
|
2021-04-29 06:22:17 -07:00
|
|
|
|
new Clean(repo).Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void ChangesInWorkTree(string repo, List<Models.Change> changes)
|
|
|
|
|
{
|
2021-04-29 06:22:17 -07:00
|
|
|
|
var needClean = new List<string>();
|
|
|
|
|
var needCheckout = new List<string>();
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
foreach (var c in changes)
|
|
|
|
|
{
|
|
|
|
|
if (c.WorkTree == Models.ChangeState.Untracked || c.WorkTree == Models.ChangeState.Added)
|
|
|
|
|
{
|
2021-04-29 06:22:17 -07:00
|
|
|
|
needClean.Add(c.Path);
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-04-29 06:22:17 -07:00
|
|
|
|
needCheckout.Add(c.Path);
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
for (int i = 0; i < needClean.Count; i += 10)
|
|
|
|
|
{
|
2021-04-29 06:22:17 -07:00
|
|
|
|
var count = Math.Min(10, needClean.Count - i);
|
|
|
|
|
new Clean(repo, needClean.GetRange(i, count)).Exec();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
for (int i = 0; i < needCheckout.Count; i += 10)
|
|
|
|
|
{
|
2021-04-29 06:22:17 -07:00
|
|
|
|
var count = Math.Min(10, needCheckout.Count - i);
|
2024-04-17 05:05:40 -07:00
|
|
|
|
new Restore(repo, needCheckout.GetRange(i, count), "--worktree --recurse-submodules").Exec();
|
2021-04-29 06:22:17 -07:00
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-02-29 19:34:32 -08:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void ChangesInStaged(string repo, List<Models.Change> changes)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < changes.Count; i += 10)
|
|
|
|
|
{
|
2024-02-29 19:34:32 -08:00
|
|
|
|
var count = Math.Min(10, changes.Count - i);
|
|
|
|
|
var files = new List<string>();
|
2024-03-31 01:54:29 -07:00
|
|
|
|
for (int j = 0; j < count; j++)
|
|
|
|
|
files.Add(changes[i + j].Path);
|
2024-04-17 05:05:40 -07:00
|
|
|
|
new Restore(repo, files, "--staged --worktree --recurse-submodules").Exec();
|
2024-02-29 19:34:32 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|