Skip to content

Commit f1052c3

Browse files
committed
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 <[email protected]>
1 parent 78f9ae2 commit f1052c3

File tree

3 files changed

+5
-29
lines changed

3 files changed

+5
-29
lines changed

src/Commands/Discard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static void All(string repo, bool includeIgnored, Models.ICommandLog log)
3636
});
3737
}
3838

39-
new Restore(repo) { Log = log }.Exec();
39+
new Reset(repo, "HEAD", "--hard") { Log = log }.Exec();
4040
if (includeIgnored)
4141
new Clean(repo) { Log = log }.Exec();
4242
}

src/Commands/Reset.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
1-
using System.Collections.Generic;
2-
using System.Text;
3-
4-
namespace SourceGit.Commands
1+
namespace SourceGit.Commands
52
{
63
public class Reset : Command
74
{
8-
public Reset(string repo)
9-
{
10-
WorkingDirectory = repo;
11-
Context = repo;
12-
Args = "reset";
13-
}
14-
15-
public Reset(string repo, List<Models.Change> changes)
16-
{
17-
WorkingDirectory = repo;
18-
Context = repo;
19-
20-
var builder = new StringBuilder();
21-
builder.Append("reset --");
22-
foreach (var c in changes)
23-
{
24-
builder.Append(" \"");
25-
builder.Append(c.Path);
26-
builder.Append("\"");
27-
}
28-
Args = builder.ToString();
29-
}
30-
315
public Reset(string repo, string revision, string mode)
326
{
337
WorkingDirectory = repo;

src/Views/TextDiffView.axaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,8 +1928,10 @@ private void OnUnstageChunk(object _1, RoutedEventArgs _2)
19281928
{
19291929
if (change.DataForAmend != null)
19301930
new Commands.UnstageChangesForAmend(repo.FullPath, [change]).Exec();
1931+
else if (change.Index == Models.ChangeState.Renamed)
1932+
new Commands.Restore(repo.FullPath, [change.Path, change.OriginalPath], "--staged").Exec();
19311933
else
1932-
new Commands.Reset(repo.FullPath, [change]).Exec();
1934+
new Commands.Restore(repo.FullPath, [change.Path], "--staged").Exec();
19331935
}
19341936
else
19351937
{

0 commit comments

Comments
 (0)