|
@@ -5,7 +5,6 @@
|
|
|
// in the public GitService API.
|
|
|
|
|
|
using System;
|
|
|
-using CliWrap;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using UnityEngine;
|
|
@@ -38,7 +37,7 @@ namespace Terra.Arbitrator.Services
|
|
|
internal static class GitExecutors
|
|
|
{
|
|
|
private static string _projectRoot;
|
|
|
- private static string ProjectRoot => _projectRoot ??= Directory.GetParent(Application.dataPath)?.FullName;
|
|
|
+ private static string ProjectRoot => _projectRoot ??= MainThreadDataCache.ProjectRoot;
|
|
|
|
|
|
public static void GetBranchDataExecutor(Action<BranchData> resolve, Action<Exception> reject)
|
|
|
{
|
|
@@ -48,10 +47,9 @@ namespace Terra.Arbitrator.Services
|
|
|
var data = new BranchData
|
|
|
{
|
|
|
CurrentBranch = repo.Head.FriendlyName,
|
|
|
- // Get all local and remote branches, then get their friendly names and remove duplicates.
|
|
|
AllBranches = repo.Branches
|
|
|
- .Where(b => !b.FriendlyName.Contains("HEAD")) // Filter out the detached HEAD entry
|
|
|
- .Select(b => b.FriendlyName.Replace("origin/", "")) // Clean up remote names
|
|
|
+ .Where(b => !b.FriendlyName.Contains("HEAD"))
|
|
|
+ .Select(b => b.FriendlyName.Replace("origin/", ""))
|
|
|
.Distinct()
|
|
|
.OrderBy(name => name)
|
|
|
.ToList()
|
|
@@ -69,7 +67,7 @@ namespace Terra.Arbitrator.Services
|
|
|
try
|
|
|
{
|
|
|
var log = new StringBuilder();
|
|
|
- await GitCommand.RunAsync(log, new[] { "checkout", branchName });
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "checkout", branchName });
|
|
|
resolve($"Successfully switched to branch '{branchName}'.");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -83,9 +81,9 @@ namespace Terra.Arbitrator.Services
|
|
|
try
|
|
|
{
|
|
|
var log = new StringBuilder();
|
|
|
- await GitCommand.RunAsync(log, new[] { "reset", "--hard", "HEAD" });
|
|
|
- await GitCommand.RunAsync(log, new[] { "clean", "-fd" });
|
|
|
- await GitCommand.RunAsync(log, new[] { "checkout", branchName });
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "reset", "--hard", "HEAD" });
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "clean", "-fd" });
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "checkout", branchName });
|
|
|
resolve($"Discarded local changes and switched to branch '{branchName}'.");
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -131,7 +129,7 @@ namespace Terra.Arbitrator.Services
|
|
|
try
|
|
|
{
|
|
|
var progressReporter = new Progress<string>(line => ParseProgress(line, onProgress));
|
|
|
- await GitCommand.RunAsync(new StringBuilder(), progressReporter, new[] { "fetch", "--progress" });
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "fetch", "--progress" }, progressReporter);
|
|
|
|
|
|
using var repo = new Repository(ProjectRoot);
|
|
|
resolve(repo.Head.TrackingDetails.BehindBy);
|
|
@@ -259,7 +257,7 @@ namespace Terra.Arbitrator.Services
|
|
|
}
|
|
|
|
|
|
var progressReporter = new Progress<string>(line => ParseProgress(line, onProgress));
|
|
|
- await GitCommand.RunAsync(new StringBuilder(), progressReporter, new[] { "push", "--progress" }, 0, 141);
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "push", "--progress" }, progressReporter, 0, 141);
|
|
|
|
|
|
resolve("Successfully committed and pushed changes!");
|
|
|
}
|
|
@@ -377,9 +375,7 @@ namespace Terra.Arbitrator.Services
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
- await Cli.Wrap(GitCommand.FindVsCodeExecutable())
|
|
|
- .WithArguments(args => args.Add("--diff").Add(fileAPath).Add(fileBPath))
|
|
|
- .ExecuteAsync();
|
|
|
+ await GitCommand.RunVsCodeAsync(new StringBuilder(), new[] { "--diff", fileAPath, fileBPath });
|
|
|
|
|
|
resolve("Launched external diff tool.");
|
|
|
}
|
|
@@ -466,17 +462,17 @@ namespace Terra.Arbitrator.Services
|
|
|
{
|
|
|
if (repo.RetrieveStatus().IsDirty)
|
|
|
{
|
|
|
- await GitCommand.RunAsync(log, new[] { "stash", "push", "-u", "-m", "BetterGit-WIP-Pull" }, 0, 141);
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "stash", "push", "-u", "-m", "BetterGit-WIP-Pull" }, 0, 141);
|
|
|
hasStashed = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- await GitCommand.RunAsync(log, new[] { "pull", "--no-rebase" }, 0, 1, 141);
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "pull", "--no-rebase" }, 0, 1, 141);
|
|
|
|
|
|
if (hasStashed)
|
|
|
{
|
|
|
- await GitCommand.RunAsync(log, new[] { "stash", "pop" }, 0, 1, 141);
|
|
|
- await GitCommand.RunAsync(log, new[] { "stash", "drop" }, 0, 141);
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "stash", "pop" }, 0, 1, 141);
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "stash", "drop" }, 0, 141);
|
|
|
}
|
|
|
|
|
|
resolve(log.ToString());
|
|
@@ -487,7 +483,7 @@ namespace Terra.Arbitrator.Services
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- await GitCommand.RunAsync(new StringBuilder(), new[] { "stash", "pop" }, 0, 1, 141);
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "stash", "pop" }, 0, 1, 141);
|
|
|
}
|
|
|
catch (Exception exception)
|
|
|
{
|
|
@@ -516,7 +512,7 @@ namespace Terra.Arbitrator.Services
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- await GitCommand.RunAsync(new StringBuilder(), new[] { GitCommand.FindVsCodeExecutable(), "--wait", change.FilePath }, 0, 141);
|
|
|
+ await GitCommand.RunVsCodeAsync(new StringBuilder(), new[] { "--wait", change.FilePath }, 0, 141);
|
|
|
|
|
|
var fullPath = Path.Combine(ProjectRoot, change.FilePath);
|
|
|
var fileContent = await File.ReadAllTextAsync(fullPath);
|
|
@@ -527,8 +523,8 @@ namespace Terra.Arbitrator.Services
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- await GitCommand.RunAsync(new StringBuilder(), new[] { "add", change.FilePath });
|
|
|
- await GitCommand.RunAsync(new StringBuilder(), new[] { "reset", "HEAD", change.FilePath });
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "add", change.FilePath });
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "reset", "HEAD", change.FilePath });
|
|
|
|
|
|
resolve($"Successfully resolved conflict in '{change.FilePath}'. The file is now modified and ready for review.");
|
|
|
}
|
|
@@ -567,7 +563,7 @@ namespace Terra.Arbitrator.Services
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- await GitCommand.RunAsync(new StringBuilder(), new[] { "reset" });
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "reset" });
|
|
|
resolve(true);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -581,8 +577,8 @@ namespace Terra.Arbitrator.Services
|
|
|
try
|
|
|
{
|
|
|
var log = new StringBuilder();
|
|
|
- await GitCommand.RunAsync(log, new[] { "reset", "--hard", "HEAD" });
|
|
|
- await GitCommand.RunAsync(log, new[] { "clean", "-fd" });
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "reset", "--hard", "HEAD" });
|
|
|
+ await GitCommand.RunGitAsync(log, new[] { "clean", "-fd" });
|
|
|
|
|
|
resolve("Successfully discarded all local changes.");
|
|
|
}
|