mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-21 18:35:00 +00:00
refactor: rewrite git restore
integration
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
80df53cf04
commit
78f9ae2fa9
5 changed files with 71 additions and 18 deletions
|
@ -5,17 +5,23 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public class Restore : Command
|
||||
{
|
||||
public Restore(string repo, bool onlyStaged)
|
||||
/// <summary>
|
||||
/// Only used to discard all changes in the working directory and staged area.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
public Restore(string repo)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
|
||||
if (onlyStaged)
|
||||
Args = "restore --source=HEAD --staged .";
|
||||
else
|
||||
Args = "restore --source=HEAD --staged --worktree --recurse-submodules .";
|
||||
Args = "restore --source=HEAD --staged --worktree --recurse-submodules .";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Discard changes with git (< 2.25.0) that does not support the `--pathspec-from-file` option.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="files"></param>
|
||||
/// <param name="extra"></param>
|
||||
public Restore(string repo, List<string> files, string extra)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
|
@ -30,5 +36,24 @@ namespace SourceGit.Commands
|
|||
builder.Append(' ').Append('"').Append(f).Append('"');
|
||||
Args = builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Discard changes with git (>= 2.25.0) that supports the `--pathspec-from-file` option.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="pathspecFile"></param>
|
||||
/// <param name="extra"></param>
|
||||
public Restore(string repo, string pathspecFile, string extra)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("restore ");
|
||||
if (!string.IsNullOrEmpty(extra))
|
||||
builder.Append(extra).Append(" ");
|
||||
builder.Append("--pathspec-from-file=\"").Append(pathspecFile).Append('"');
|
||||
Args = builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue