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 <longshuang@msn.cn>
This commit is contained in:
leo 2025-06-02 12:50:58 +08:00
parent 78f9ae2fa9
commit f1052c3efc
No known key found for this signature in database
3 changed files with 5 additions and 29 deletions

View file

@ -36,7 +36,7 @@ namespace SourceGit.Commands
}); });
} }
new Restore(repo) { Log = log }.Exec(); new Reset(repo, "HEAD", "--hard") { Log = log }.Exec();
if (includeIgnored) if (includeIgnored)
new Clean(repo) { Log = log }.Exec(); new Clean(repo) { Log = log }.Exec();
} }

View file

@ -1,33 +1,7 @@
using System.Collections.Generic; namespace SourceGit.Commands
using System.Text;
namespace SourceGit.Commands
{ {
public class Reset : Command public class Reset : Command
{ {
public Reset(string repo)
{
WorkingDirectory = repo;
Context = repo;
Args = "reset";
}
public Reset(string repo, List<Models.Change> 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) public Reset(string repo, string revision, string mode)
{ {
WorkingDirectory = repo; WorkingDirectory = repo;

View file

@ -1928,8 +1928,10 @@ namespace SourceGit.Views
{ {
if (change.DataForAmend != null) if (change.DataForAmend != null)
new Commands.UnstageChangesForAmend(repo.FullPath, [change]).Exec(); 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 else
new Commands.Reset(repo.FullPath, [change]).Exec(); new Commands.Restore(repo.FullPath, [change.Path], "--staged").Exec();
} }
else else
{ {