mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-24 03:45:00 +00:00
feature!: now SourceGit
requires git >= 2.25.1
Some checks are pending
Some checks are pending
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
7b05b011aa
commit
6e501b1ee4
21 changed files with 97 additions and 139 deletions
|
@ -1,7 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SourceGit.Commands
|
||||
namespace SourceGit.Commands
|
||||
{
|
||||
public class Add : Command
|
||||
{
|
||||
|
@ -12,20 +9,11 @@ namespace SourceGit.Commands
|
|||
Args = includeUntracked ? "add ." : "add -u .";
|
||||
}
|
||||
|
||||
public Add(string repo, List<string> changes)
|
||||
public Add(string repo, Models.Change change)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("add --");
|
||||
foreach (var c in changes)
|
||||
{
|
||||
builder.Append(" \"");
|
||||
builder.Append(c);
|
||||
builder.Append("\"");
|
||||
}
|
||||
Args = builder.ToString();
|
||||
Args = $"add -- \"{change.Path}\"";
|
||||
}
|
||||
|
||||
public Add(string repo, string pathspecFromFile)
|
||||
|
|
|
@ -8,6 +8,12 @@ namespace SourceGit.Commands
|
|||
{
|
||||
public static class Discard
|
||||
{
|
||||
/// <summary>
|
||||
/// Discard all local changes (unstaged & staged)
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="includeIgnored"></param>
|
||||
/// <param name="log"></param>
|
||||
public static void All(string repo, bool includeIgnored, Models.ICommandLog log)
|
||||
{
|
||||
var changes = new QueryLocalChanges(repo).Result();
|
||||
|
@ -37,10 +43,17 @@ namespace SourceGit.Commands
|
|||
}
|
||||
|
||||
new Reset(repo, "HEAD", "--hard") { Log = log }.Exec();
|
||||
|
||||
if (includeIgnored)
|
||||
new Clean(repo) { Log = log }.Exec();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Discard selected changes (only unstaged).
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="changes"></param>
|
||||
/// <param name="log"></param>
|
||||
public static void Changes(string repo, List<Models.Change> changes, Models.ICommandLog log)
|
||||
{
|
||||
var restores = new List<string>();
|
||||
|
@ -71,20 +84,12 @@ namespace SourceGit.Commands
|
|||
});
|
||||
}
|
||||
|
||||
if (Native.OS.GitVersion >= Models.GitVersions.RESTORE_WITH_PATHSPECFILE)
|
||||
if (restores.Count > 0)
|
||||
{
|
||||
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();
|
||||
}
|
||||
var pathSpecFile = Path.GetTempFileName();
|
||||
File.WriteAllLines(pathSpecFile, restores);
|
||||
new Restore(repo, pathSpecFile, false) { Log = log }.Exec();
|
||||
File.Delete(pathSpecFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +1,52 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace SourceGit.Commands
|
||||
{
|
||||
public class Restore : Command
|
||||
{
|
||||
/// <summary>
|
||||
/// Only used to discard all changes in the working directory and staged area.
|
||||
/// Only used for single staged change.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
public Restore(string repo)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
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)
|
||||
/// <param name="stagedChange"></param>
|
||||
public Restore(string repo, Models.Change stagedChange)
|
||||
{
|
||||
WorkingDirectory = repo;
|
||||
Context = repo;
|
||||
|
||||
var builder = new StringBuilder();
|
||||
builder.Append("restore ");
|
||||
if (!string.IsNullOrEmpty(extra))
|
||||
builder.Append(extra).Append(" ");
|
||||
builder.Append("--");
|
||||
foreach (var f in files)
|
||||
builder.Append(' ').Append('"').Append(f).Append('"');
|
||||
builder.Append("restore --staged -- \"");
|
||||
builder.Append(stagedChange.Path);
|
||||
builder.Append('"');
|
||||
|
||||
if (stagedChange.Index == Models.ChangeState.Renamed)
|
||||
{
|
||||
builder.Append(" \"");
|
||||
builder.Append(stagedChange.OriginalPath);
|
||||
builder.Append('"');
|
||||
}
|
||||
|
||||
Args = builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Discard changes with git (>= 2.25.0) that supports the `--pathspec-from-file` option.
|
||||
/// Restore changes given in a path-spec file.
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
/// <param name="pathspecFile"></param>
|
||||
/// <param name="extra"></param>
|
||||
public Restore(string repo, string pathspecFile, string extra)
|
||||
/// <param name="isStaged"></param>
|
||||
public Restore(string repo, string pathspecFile, bool isStaged)
|
||||
{
|
||||
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('"');
|
||||
builder.Append(isStaged ? "--staged " : "--worktree --recurse-submodules ");
|
||||
builder.Append("--pathspec-from-file=\"");
|
||||
builder.Append(pathspecFile);
|
||||
builder.Append('"');
|
||||
|
||||
Args = builder.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,12 +28,13 @@ namespace SourceGit.Commands
|
|||
string tmp = Path.GetTempFileName();
|
||||
File.WriteAllText(tmp, message);
|
||||
cmd.Args += $"-F \"{tmp}\"";
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.Args += $"-m {name}";
|
||||
|
||||
var succ = cmd.Exec();
|
||||
File.Delete(tmp);
|
||||
return succ;
|
||||
}
|
||||
|
||||
cmd.Args += $"-m {name}";
|
||||
return cmd.Exec();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue