refactor: use git reset HEAD --pathspec-from-file=<pathspec> instead of git restore --staged --pathspec-from-file=<pathspec> to unstage files

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-12-26 16:57:42 +08:00
parent 974c30b39c
commit e30ed896e2
4 changed files with 12 additions and 13 deletions

View File

@@ -86,7 +86,7 @@ namespace SourceGit.Commands
{
var pathSpecFile = Path.GetTempFileName();
await File.WriteAllLinesAsync(pathSpecFile, restores).ConfigureAwait(false);
await new Restore(repo, pathSpecFile, false).Use(log).ExecAsync().ConfigureAwait(false);
await new Restore(repo, pathSpecFile).Use(log).ExecAsync().ConfigureAwait(false);
File.Delete(pathSpecFile);
}
}

View File

@@ -8,5 +8,12 @@
Context = repo;
Args = $"reset {mode} {revision}";
}
public Reset(string repo, string pathspec)
{
WorkingDirectory = repo;
Context = repo;
Args = $"reset HEAD --pathspec-from-file={pathspec.Quoted()}";
}
}
}

View File

@@ -1,20 +1,12 @@
using System.Text;
namespace SourceGit.Commands
namespace SourceGit.Commands
{
public class Restore : Command
{
public Restore(string repo, string pathspecFile, bool isStaged)
public Restore(string repo, string pathspecFile)
{
WorkingDirectory = repo;
Context = repo;
var builder = new StringBuilder();
builder.Append("restore --progress ");
builder.Append(isStaged ? "--staged " : "--worktree --recurse-submodules ");
builder.Append("--pathspec-from-file=").Append(pathspecFile.Quoted());
Args = builder.ToString();
Args = $"restore --progress --worktree --recurse-submodules --pathspec-from-file={pathspecFile.Quoted()}";
}
}
}

View File

@@ -393,7 +393,7 @@ namespace SourceGit.ViewModels
}
}
await new Commands.Restore(_repo.FullPath, pathSpecFile, true).Use(log).ExecAsync();
await new Commands.Reset(_repo.FullPath, pathSpecFile).Use(log).ExecAsync();
File.Delete(pathSpecFile);
}
log.Complete();