mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-07 11:54:59 +00:00
refactor: use git restore
instead of git reset
to unstage local changes (#1373)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
46231a759c
commit
e40ca4bbe0
3 changed files with 13 additions and 5 deletions
|
@ -36,7 +36,7 @@ namespace SourceGit.Commands
|
|||
});
|
||||
}
|
||||
|
||||
new Restore(repo) { Log = log }.Exec();
|
||||
new Restore(repo, false) { Log = log }.Exec();
|
||||
if (includeIgnored)
|
||||
new Clean(repo) { Log = log }.Exec();
|
||||
}
|
||||
|
|
|
@ -5,11 +5,15 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public class Restore : Command
|
||||
{
|
||||
public Restore(string repo)
|
||||
public Restore(string repo, bool onlyStaged)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
Args = "restore . --source=HEAD --staged --worktree --recurse-submodules";
|
||||
|
||||
if (onlyStaged)
|
||||
Args = "restore --source=HEAD --staged .";
|
||||
else
|
||||
Args = "restore --source=HEAD --staged --worktree --recurse-submodules .";
|
||||
}
|
||||
|
||||
public Restore(string repo, List<string> files, string extra)
|
||||
|
|
|
@ -1664,14 +1664,18 @@ namespace SourceGit.ViewModels
|
|||
}
|
||||
else if (count == _staged.Count)
|
||||
{
|
||||
await Task.Run(() => new Commands.Reset(_repo.FullPath).Use(log).Exec());
|
||||
await Task.Run(() => new Commands.Restore(_repo.FullPath, true).Use(log).Exec());
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < count; i += 10)
|
||||
{
|
||||
var step = changes.GetRange(i, Math.Min(10, count - i));
|
||||
await Task.Run(() => new Commands.Reset(_repo.FullPath, step).Use(log).Exec());
|
||||
var files = new List<string>();
|
||||
foreach (var c in step)
|
||||
files.Add(c.Path);
|
||||
|
||||
await Task.Run(() => new Commands.Restore(_repo.FullPath, files, "--staged").Use(log).Exec());
|
||||
}
|
||||
}
|
||||
log.Complete();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue