mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-23 19:34:59 +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
|
@ -36,7 +36,7 @@ namespace SourceGit.Commands
|
|||
});
|
||||
}
|
||||
|
||||
new Restore(repo, false) { Log = log }.Exec();
|
||||
new Restore(repo) { Log = log }.Exec();
|
||||
if (includeIgnored)
|
||||
new Clean(repo) { Log = log }.Exec();
|
||||
}
|
||||
|
@ -71,10 +71,20 @@ namespace SourceGit.Commands
|
|||
});
|
||||
}
|
||||
|
||||
for (int i = 0; i < restores.Count; i += 10)
|
||||
if (Native.OS.GitVersion >= Models.GitVersions.RESTORE_WITH_PATHSPECFILE)
|
||||
{
|
||||
var count = Math.Min(10, restores.Count - i);
|
||||
new Restore(repo, restores.GetRange(i, count), "--worktree --recurse-submodules") { Log = log }.Exec();
|
||||
var tmpFile = Path.GetTempFileName();
|
||||
File.WriteAllLines(tmpFile, restores);
|
||||
new Restore(repo, tmpFile, "--worktree --recurse-submodules") { Log = log }.Exec();
|
||||
File.Delete(tmpFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < restores.Count; i += 32)
|
||||
{
|
||||
var count = Math.Min(32, restores.Count - i);
|
||||
new Restore(repo, restores.GetRange(i, count), "--worktree --recurse-submodules") { Log = log }.Exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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