From f1052c3efc61bd762b7fb560dee8d099edb00bcd Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 2 Jun 2025 12:50:58 +0800 Subject: [PATCH] refactor: use `git reset --hard HEAD` to discard all changes and use `git restore --staged` to unstage changes in text diff view Signed-off-by: leo --- src/Commands/Discard.cs | 2 +- src/Commands/Reset.cs | 28 +--------------------------- src/Views/TextDiffView.axaml.cs | 4 +++- 3 files changed, 5 insertions(+), 29 deletions(-) diff --git a/src/Commands/Discard.cs b/src/Commands/Discard.cs index 0c3854c8..0768ca67 100644 --- a/src/Commands/Discard.cs +++ b/src/Commands/Discard.cs @@ -36,7 +36,7 @@ namespace SourceGit.Commands }); } - new Restore(repo) { Log = log }.Exec(); + new Reset(repo, "HEAD", "--hard") { Log = log }.Exec(); if (includeIgnored) new Clean(repo) { Log = log }.Exec(); } diff --git a/src/Commands/Reset.cs b/src/Commands/Reset.cs index da272135..6a54533b 100644 --- a/src/Commands/Reset.cs +++ b/src/Commands/Reset.cs @@ -1,33 +1,7 @@ -using System.Collections.Generic; -using System.Text; - -namespace SourceGit.Commands +namespace SourceGit.Commands { public class Reset : Command { - public Reset(string repo) - { - WorkingDirectory = repo; - Context = repo; - Args = "reset"; - } - - public Reset(string repo, List changes) - { - WorkingDirectory = repo; - Context = repo; - - var builder = new StringBuilder(); - builder.Append("reset --"); - foreach (var c in changes) - { - builder.Append(" \""); - builder.Append(c.Path); - builder.Append("\""); - } - Args = builder.ToString(); - } - public Reset(string repo, string revision, string mode) { WorkingDirectory = repo; diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 81827a1e..8ad4a223 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -1928,8 +1928,10 @@ namespace SourceGit.Views { if (change.DataForAmend != null) new Commands.UnstageChangesForAmend(repo.FullPath, [change]).Exec(); + else if (change.Index == Models.ChangeState.Renamed) + new Commands.Restore(repo.FullPath, [change.Path, change.OriginalPath], "--staged").Exec(); else - new Commands.Reset(repo.FullPath, [change]).Exec(); + new Commands.Restore(repo.FullPath, [change.Path], "--staged").Exec(); } else {