From e30ed896e22e92bcfed0c0bb4375d203526d562d Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 26 Dec 2025 16:57:42 +0800 Subject: [PATCH] refactor: use `git reset HEAD --pathspec-from-file=` instead of `git restore --staged --pathspec-from-file=` to unstage files Signed-off-by: leo --- src/Commands/Discard.cs | 2 +- src/Commands/Reset.cs | 7 +++++++ src/Commands/Restore.cs | 14 +++----------- src/ViewModels/WorkingCopy.cs | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Commands/Discard.cs b/src/Commands/Discard.cs index cbf38bd4..aad58911 100644 --- a/src/Commands/Discard.cs +++ b/src/Commands/Discard.cs @@ -86,7 +86,7 @@ namespace SourceGit.Commands { var pathSpecFile = Path.GetTempFileName(); await File.WriteAllLinesAsync(pathSpecFile, restores).ConfigureAwait(false); - await new Restore(repo, pathSpecFile, false).Use(log).ExecAsync().ConfigureAwait(false); + await new Restore(repo, pathSpecFile).Use(log).ExecAsync().ConfigureAwait(false); File.Delete(pathSpecFile); } } diff --git a/src/Commands/Reset.cs b/src/Commands/Reset.cs index 6a54533b..cfcd337a 100644 --- a/src/Commands/Reset.cs +++ b/src/Commands/Reset.cs @@ -8,5 +8,12 @@ Context = repo; Args = $"reset {mode} {revision}"; } + + public Reset(string repo, string pathspec) + { + WorkingDirectory = repo; + Context = repo; + Args = $"reset HEAD --pathspec-from-file={pathspec.Quoted()}"; + } } } diff --git a/src/Commands/Restore.cs b/src/Commands/Restore.cs index 49b760a4..bf3bd0a5 100644 --- a/src/Commands/Restore.cs +++ b/src/Commands/Restore.cs @@ -1,20 +1,12 @@ -using System.Text; - -namespace SourceGit.Commands +namespace SourceGit.Commands { public class Restore : Command { - public Restore(string repo, string pathspecFile, bool isStaged) + public Restore(string repo, string pathspecFile) { WorkingDirectory = repo; Context = repo; - - var builder = new StringBuilder(); - builder.Append("restore --progress "); - builder.Append(isStaged ? "--staged " : "--worktree --recurse-submodules "); - builder.Append("--pathspec-from-file=").Append(pathspecFile.Quoted()); - - Args = builder.ToString(); + Args = $"restore --progress --worktree --recurse-submodules --pathspec-from-file={pathspecFile.Quoted()}"; } } } diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 578b3fd8..e8838721 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -393,7 +393,7 @@ namespace SourceGit.ViewModels } } - await new Commands.Restore(_repo.FullPath, pathSpecFile, true).Use(log).ExecAsync(); + await new Commands.Reset(_repo.FullPath, pathSpecFile).Use(log).ExecAsync(); File.Delete(pathSpecFile); } log.Complete();