enhance: use restore instead of reset to discard changes (#76)

This commit is contained in:
leo 2024-04-17 20:05:40 +08:00
parent 60a4d21ce7
commit 8378f018b1
2 changed files with 10 additions and 3 deletions

View file

@ -7,7 +7,7 @@ namespace SourceGit.Commands
{ {
public static void All(string repo) public static void All(string repo)
{ {
new Reset(repo, "HEAD", "--hard").Exec(); new Restore(repo).Exec();
new Clean(repo).Exec(); new Clean(repo).Exec();
} }
@ -37,7 +37,7 @@ namespace SourceGit.Commands
for (int i = 0; i < needCheckout.Count; i += 10) for (int i = 0; i < needCheckout.Count; i += 10)
{ {
var count = Math.Min(10, needCheckout.Count - i); var count = Math.Min(10, needCheckout.Count - i);
new Checkout(repo).Files(needCheckout.GetRange(i, count)); new Restore(repo, needCheckout.GetRange(i, count), "--worktree --recurse-submodules").Exec();
} }
} }
@ -49,7 +49,7 @@ namespace SourceGit.Commands
var files = new List<string>(); var files = new List<string>();
for (int j = 0; j < count; j++) for (int j = 0; j < count; j++)
files.Add(changes[i + j].Path); files.Add(changes[i + j].Path);
new Restore(repo, files, "--staged --worktree").Exec(); new Restore(repo, files, "--staged --worktree --recurse-submodules").Exec();
} }
} }
} }

View file

@ -5,6 +5,13 @@ namespace SourceGit.Commands
{ {
public class Restore : Command public class Restore : Command
{ {
public Restore(string repo)
{
WorkingDirectory = repo;
Context = repo;
Args = "restore . --source=HEAD --staged --worktree --recurse-submodules";
}
public Restore(string repo, List<string> files, string extra) public Restore(string repo, List<string> files, string extra)
{ {
WorkingDirectory = repo; WorkingDirectory = repo;