Skip to content

Commit 8378f01

Browse files
committed
enhance: use restore instead of reset to discard changes (#76)
1 parent 60a4d21 commit 8378f01

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Commands/Discard.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class Discard
77
{
88
public static void All(string repo)
99
{
10-
new Reset(repo, "HEAD", "--hard").Exec();
10+
new Restore(repo).Exec();
1111
new Clean(repo).Exec();
1212
}
1313

@@ -37,7 +37,7 @@ public static void ChangesInWorkTree(string repo, List<Models.Change> changes)
3737
for (int i = 0; i < needCheckout.Count; i += 10)
3838
{
3939
var count = Math.Min(10, needCheckout.Count - i);
40-
new Checkout(repo).Files(needCheckout.GetRange(i, count));
40+
new Restore(repo, needCheckout.GetRange(i, count), "--worktree --recurse-submodules").Exec();
4141
}
4242
}
4343

@@ -49,7 +49,7 @@ public static void ChangesInStaged(string repo, List<Models.Change> changes)
4949
var files = new List<string>();
5050
for (int j = 0; j < count; j++)
5151
files.Add(changes[i + j].Path);
52-
new Restore(repo, files, "--staged --worktree").Exec();
52+
new Restore(repo, files, "--staged --worktree --recurse-submodules").Exec();
5353
}
5454
}
5555
}

src/Commands/Restore.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ namespace SourceGit.Commands
55
{
66
public class Restore : Command
77
{
8+
public Restore(string repo)
9+
{
10+
WorkingDirectory = repo;
11+
Context = repo;
12+
Args = "restore . --source=HEAD --staged --worktree --recurse-submodules";
13+
}
14+
815
public Restore(string repo, List<string> files, string extra)
916
{
1017
WorkingDirectory = repo;

0 commit comments

Comments
 (0)