|
@@ -8,14 +8,15 @@ using System;
|
|
|
using System.IO;
|
|
|
using System.Linq;
|
|
|
using UnityEngine;
|
|
|
-using LibGit2Sharp;
|
|
|
using System.Text;
|
|
|
+using LibGit2Sharp;
|
|
|
using System.Globalization;
|
|
|
using System.ComponentModel;
|
|
|
using UnityEngine.Scripting;
|
|
|
using System.Threading.Tasks;
|
|
|
using Terra.Arbitrator.Settings;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
|
|
namespace Terra.Arbitrator.Services
|
|
|
{
|
|
@@ -39,6 +40,29 @@ namespace Terra.Arbitrator.Services
|
|
|
private static string _projectRoot;
|
|
|
private static string ProjectRoot => _projectRoot ??= MainThreadDataCache.ProjectRoot;
|
|
|
|
|
|
+ private static string GetAuthenticatedRemoteUrl()
|
|
|
+ {
|
|
|
+ var authUsername = BetterGitSettings.AuthUsername;
|
|
|
+ var authPassword = BetterGitSettings.AuthPassword;
|
|
|
+
|
|
|
+ if (string.IsNullOrEmpty(authUsername) || string.IsNullOrEmpty(authPassword))
|
|
|
+ {
|
|
|
+ return "origin";
|
|
|
+ }
|
|
|
+
|
|
|
+ using var repo = new Repository(ProjectRoot);
|
|
|
+ var remote = repo.Network.Remotes["origin"];
|
|
|
+ if (remote == null) throw new Exception("No remote named 'origin' found.");
|
|
|
+
|
|
|
+ var originalUrl = remote.Url;
|
|
|
+
|
|
|
+ var authenticatedUrl = Regex.Replace(originalUrl,
|
|
|
+ @"://",
|
|
|
+ $"://{Uri.EscapeDataString(authUsername)}:{Uri.EscapeDataString(authPassword)}@");
|
|
|
+
|
|
|
+ return authenticatedUrl;
|
|
|
+ }
|
|
|
+
|
|
|
public static void GetBranchDataExecutor(Action<BranchData> resolve, Action<Exception> reject)
|
|
|
{
|
|
|
try
|
|
@@ -128,8 +152,9 @@ namespace Terra.Arbitrator.Services
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ var authenticatedUrl = GetAuthenticatedRemoteUrl();
|
|
|
var progressReporter = new Progress<string>(line => ParseProgress(line, onProgress));
|
|
|
- await GitCommand.RunGitAsync(new StringBuilder(), new[] { "fetch", "--progress" }, progressReporter);
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "fetch", authenticatedUrl, "--progress" }, progressReporter);
|
|
|
|
|
|
using var repo = new Repository(ProjectRoot);
|
|
|
resolve(repo.Head.TrackingDetails.BehindBy);
|
|
@@ -216,7 +241,8 @@ namespace Terra.Arbitrator.Services
|
|
|
throw new Exception("Author email is missing. Please set your email address in Project Settings > Better Git.");
|
|
|
}
|
|
|
|
|
|
- await GitCommand.RunGitAsync(new StringBuilder(), new[] { "fetch" });
|
|
|
+ var authenticatedUrl = GetAuthenticatedRemoteUrl();
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "fetch", authenticatedUrl });
|
|
|
|
|
|
using (var repo = new Repository(ProjectRoot))
|
|
|
{
|
|
@@ -259,7 +285,9 @@ namespace Terra.Arbitrator.Services
|
|
|
}
|
|
|
|
|
|
var progressReporter = new Progress<string>(line => ParseProgress(line, onProgress));
|
|
|
- await GitCommand.RunGitAsync(new StringBuilder(), new[] { "push", "--progress" }, progressReporter, 0, 141);
|
|
|
+ using var tempRepo = new Repository(ProjectRoot);
|
|
|
+ var currentBranch = tempRepo.Head.FriendlyName;
|
|
|
+ await GitCommand.RunGitAsync(new StringBuilder(), new[] { "push", "--progress", authenticatedUrl, $"HEAD:{currentBranch}" }, progressReporter, 0, 141);
|
|
|
|
|
|
resolve("Successfully committed and pushed changes!");
|
|
|
}
|
|
@@ -573,21 +601,5 @@ namespace Terra.Arbitrator.Services
|
|
|
reject(ex);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- public static async void ResetAllChangesExecutor(Action<string> resolve, Action<Exception> reject)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- var log = new StringBuilder();
|
|
|
- await GitCommand.RunGitAsync(log, new[] { "reset", "--hard", "HEAD" });
|
|
|
- await GitCommand.RunGitAsync(log, new[] { "clean", "-fd" });
|
|
|
-
|
|
|
- resolve("Successfully discarded all local changes.");
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- reject(ex);
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
}
|