Skip to content

Commit e40ca4b

Browse files
committed
refactor: use git restore instead of git reset to unstage local changes (#1373)
Signed-off-by: leo <[email protected]>
1 parent 46231a7 commit e40ca4b

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
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 Restore(repo, false) { Log = log }.Exec();
4040
if (includeIgnored)
4141
new Clean(repo) { Log = log }.Exec();
4242
}

src/Commands/Restore.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@ namespace SourceGit.Commands
55
{
66
public class Restore : Command
77
{
8-
public Restore(string repo)
8+
public Restore(string repo, bool onlyStaged)
99
{
1010
WorkingDirectory = repo;
1111
Context = repo;
12-
Args = "restore . --source=HEAD --staged --worktree --recurse-submodules";
12+
13+
if (onlyStaged)
14+
Args = "restore --source=HEAD --staged .";
15+
else
16+
Args = "restore --source=HEAD --staged --worktree --recurse-submodules .";
1317
}
1418

1519
public Restore(string repo, List<string> files, string extra)

src/ViewModels/WorkingCopy.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,14 +1664,18 @@ private async void UnstageChanges(List<Models.Change> changes, Models.Change nex
16641664
}
16651665
else if (count == _staged.Count)
16661666
{
1667-
await Task.Run(() => new Commands.Reset(_repo.FullPath).Use(log).Exec());
1667+
await Task.Run(() => new Commands.Restore(_repo.FullPath, true).Use(log).Exec());
16681668
}
16691669
else
16701670
{
16711671
for (int i = 0; i < count; i += 10)
16721672
{
16731673
var step = changes.GetRange(i, Math.Min(10, count - i));
1674-
await Task.Run(() => new Commands.Reset(_repo.FullPath, step).Use(log).Exec());
1674+
var files = new List<string>();
1675+
foreach (var c in step)
1676+
files.Add(c.Path);
1677+
1678+
await Task.Run(() => new Commands.Restore(_repo.FullPath, files, "--staged").Use(log).Exec());
16751679
}
16761680
}
16771681
log.Complete();

0 commit comments

Comments
 (0)