Bläddra i källkod

Sujith :) ->
1. Added progress bar while fetching as well

sujith 1 månad sedan
förälder
incheckning
fd35fa38ec

+ 15 - 9
Assets/Arbitrator/Editor/GUI/ArbitratorController.cs

@@ -30,8 +30,8 @@ namespace Terra.Arbitrator.GUI
         public bool IsInConflictState { get; private set; }
         public int CommitsToPull { get; private set; }
         public SortColumn CurrentSortColumn { get; private set; } = SortColumn.FilePath;
-        public float PushProgress { get; private set; }
-        public string PushProgressMessage { get; private set; }
+        public float OperationProgress { get; private set; }
+        public string OperationProgressMessage { get; private set; }
         public IReadOnlyList<string> RemoteBranchList { get; private set; } = new List<string>();
         public string CurrentBranchName { get; private set; } = "master";
 
@@ -172,8 +172,8 @@ namespace Terra.Arbitrator.GUI
 
             void OnProgressModified(float progress, string message)
             {
-                PushProgress = progress;
-                PushProgressMessage = message;
+                OperationProgress = progress;
+                OperationProgressMessage = message;
                 _requestRepaint?.Invoke();
             }
         }
@@ -344,15 +344,21 @@ namespace Terra.Arbitrator.GUI
         {
             _changes = changes;
             IsInConflictState = _changes.Any(c => c.Status == LibGit2Sharp.ChangeKind.Conflicted);
+            return IsInConflictState ? new Promise<int?>((resolve, _) => resolve(0)) : GitService.GetUpstreamAheadBy(OnProgressModified);
 
-            return IsInConflictState ?
-                // If in conflict, we can't pull, so we don't need to check. Return a resolved promise.
-                new Promise<int?>((resolve, _) => resolve(0)) : GitService.GetUpstreamAheadBy();
+            void OnProgressModified(float progress, string message)
+            {
+                OperationProgress = progress;
+                OperationProgressMessage = message;
+                _requestRepaint?.Invoke();
+            }
         }
 
         private IPromise<BranchData> FetchBranchDataStep(int? pullCount)
         {
             CommitsToPull = pullCount ?? 0;
+            OperationProgress = 0f;
+            OperationProgressMessage = "";
             return GitService.GetBranchData();
         }
 
@@ -369,8 +375,8 @@ namespace Terra.Arbitrator.GUI
         {
             IsLoading = true;
             LoadingMessage = loadingMessage;
-            PushProgress = 0f;
-            PushProgressMessage = "";
+            OperationProgress = 0f;
+            OperationProgressMessage = "";
             ClearMessages();
             _changes = null;
             _requestRepaint?.Invoke();

+ 3 - 3
Assets/Arbitrator/Editor/GUI/ArbitratorWindow.cs

@@ -168,11 +168,11 @@ namespace Terra.Arbitrator.GUI
             if (_controller.IsLoading)
             {
                 GUILayout.FlexibleSpace();
-                if (_controller.PushProgress > 0)
+                if (_controller.OperationProgress > 0)
                 {
-                    EditorGUILayout.LabelField(_controller.PushProgressMessage, EditorStyles.centeredGreyMiniLabel);
+                    EditorGUILayout.LabelField(_controller.OperationProgressMessage, EditorStyles.centeredGreyMiniLabel);
                     var rect = EditorGUILayout.GetControlRect(false, 20);
-                    EditorGUI.ProgressBar(rect, _controller.PushProgress, $"{_controller.PushProgress:P0}");
+                    EditorGUI.ProgressBar(rect, _controller.OperationProgress, $"{_controller.OperationProgress:P0}");
                 }
                 else
                 {

+ 7 - 5
Assets/Arbitrator/Editor/Services/GitExecutors.cs

@@ -123,11 +123,13 @@ namespace Terra.Arbitrator.Services
         
         // --- Promise Executor Implementations ---
         
-        public static async void GetUpstreamAheadByExecutor(Action<int?> resolve, Action<Exception> reject)
+        public static async void GetUpstreamAheadByExecutor(Action<int?> resolve, Action<Exception> reject, Action<float, string> onProgress)
         {
             try
             {
-                await GitCommand.RunAsync(new StringBuilder(), new[] { "fetch" });
+                var progressReporter = new Progress<string>(line => ParseProgress(line, onProgress));
+                await GitCommand.RunAsync(new StringBuilder(), progressReporter, new[] { "fetch", "--progress" });
+
                 using var repo = new Repository(ProjectRoot);
                 resolve(repo.Head.TrackingDetails.BehindBy);
             }
@@ -242,7 +244,7 @@ namespace Terra.Arbitrator.Services
                     repo.Commit(commitMessage, author, author);
                 }
 
-                var progressReporter = new Progress<string>(line => ParsePushProgress(line, onProgress));
+                var progressReporter = new Progress<string>(line => ParseProgress(line, onProgress));
                 await GitCommand.RunAsync(new StringBuilder(), progressReporter, new[] { "push", "--progress" }, 0, 141);
 
                 resolve("Successfully committed and pushed changes!");
@@ -254,7 +256,7 @@ namespace Terra.Arbitrator.Services
             }
         }
         
-        private static void ParsePushProgress(string line, Action<float, string> onProgress)
+        private static void ParseProgress(string line, Action<float, string> onProgress)
         {
             if (onProgress == null || string.IsNullOrWhiteSpace(line)) return;
 
@@ -268,7 +270,7 @@ namespace Terra.Arbitrator.Services
             var percentIndex = progressPart.IndexOf('%');
             if (percentIndex == -1) return;
 
-            var percentString = progressPart.Substring(0, percentIndex).Trim();
+            var percentString = progressPart[..percentIndex].Trim();
             if (!float.TryParse(percentString, NumberStyles.Any, CultureInfo.InvariantCulture, out var percentage)) return;
             var progressValue = percentage / 100.0f;
             onProgress(progressValue, $"{action}...");

+ 2 - 2
Assets/Arbitrator/Editor/Services/GitService.cs

@@ -53,9 +53,9 @@ namespace Terra.Arbitrator.Services
         /// Gets the number of incoming commits from the tracked remote branch.
         /// </summary>
         /// <returns>A promise that resolves with the number of commits, or null if not tracked.</returns>
-        public static IPromise<int?> GetUpstreamAheadBy()
+        public static IPromise<int?> GetUpstreamAheadBy(Action<float, string> onProgress = null)
         {
-            return new Promise<int?>(GitExecutors.GetUpstreamAheadByExecutor);
+            return new Promise<int?>((resolve, reject) => GitExecutors.GetUpstreamAheadByExecutor(resolve, reject, onProgress));
         }
         
         /// <summary>