From 8378f018b1f3b94824ba45620056cd67f45f3ad5 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 17 Apr 2024 20:05:40 +0800 Subject: [PATCH] enhance: use `restore` instead of `reset` to discard changes (#76) --- src/Commands/Discard.cs | 6 +++--- src/Commands/Restore.cs | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Commands/Discard.cs b/src/Commands/Discard.cs index 072dc59a..22b579a3 100644 --- a/src/Commands/Discard.cs +++ b/src/Commands/Discard.cs @@ -7,7 +7,7 @@ namespace SourceGit.Commands { public static void All(string repo) { - new Reset(repo, "HEAD", "--hard").Exec(); + new Restore(repo).Exec(); new Clean(repo).Exec(); } @@ -37,7 +37,7 @@ namespace SourceGit.Commands for (int i = 0; i < needCheckout.Count; i += 10) { 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(); for (int j = 0; j < count; j++) files.Add(changes[i + j].Path); - new Restore(repo, files, "--staged --worktree").Exec(); + new Restore(repo, files, "--staged --worktree --recurse-submodules").Exec(); } } } diff --git a/src/Commands/Restore.cs b/src/Commands/Restore.cs index 12a2eaa1..7a363543 100644 --- a/src/Commands/Restore.cs +++ b/src/Commands/Restore.cs @@ -5,6 +5,13 @@ namespace SourceGit.Commands { 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 files, string extra) { WorkingDirectory = repo;