Sfoglia il codice sorgente

Sujith :) ->
1. Added push progress bar

sujith 1 mese fa
parent
commit
25ce2fc64d

+ 13 - 5
Assets/Arbitrator/Editor/GUI/ArbitratorController.cs

@@ -30,6 +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; }
 
         private readonly Action _requestRepaint;
         private readonly Func<string, string, string, string, bool> _displayDialog;
@@ -154,7 +156,7 @@ namespace Terra.Arbitrator.GUI
             
             StartOperation("Staging, committing, and pushing files...");
 
-            GitService.CommitAndPush(selectedFiles, commitMessage, username, email)
+            GitService.CommitAndPush(selectedFiles, commitMessage, username, email, OnProgressModified)
                 .Then(successMessage => {
                     InfoMessage = successMessage;
                     Refresh();
@@ -163,6 +165,14 @@ namespace Terra.Arbitrator.GUI
                     HandleOperationError(ex);
                     FinishOperation();
                 });
+            return;
+
+            void OnProgressModified(float progress, string message)
+            {
+                PushProgress = progress;
+                PushProgressMessage = message;
+                _requestRepaint?.Invoke();
+            }
         }
         
         public void SetSortColumn(SortColumn newColumn)
@@ -308,10 +318,6 @@ namespace Terra.Arbitrator.GUI
         private void FinalizeRefresh(int? pullCount)
         {
             CommitsToPull = pullCount ?? 0;
-            if (string.IsNullOrEmpty(InfoMessage) && (_changes == null || _changes.Count == 0))
-            {
-                InfoMessage = "You are up-to-date! No local changes detected.";
-            }
         }
         
         // --- Shared Helper Methods ---
@@ -320,6 +326,8 @@ namespace Terra.Arbitrator.GUI
         {
             IsLoading = true;
             LoadingMessage = loadingMessage;
+            PushProgress = 0f;
+            PushProgressMessage = "";
             ClearMessages();
             _changes = null;
             _requestRepaint?.Invoke();

+ 14 - 5
Assets/Arbitrator/Editor/GUI/ArbitratorWindow.cs

@@ -153,11 +153,20 @@ namespace Terra.Arbitrator.GUI
             if (_controller.IsLoading)
             {
                 GUILayout.FlexibleSpace();
-                EditorGUILayout.BeginHorizontal();
-                GUILayout.FlexibleSpace();
-                GUILayout.Label("Loading...", EditorStyles.largeLabel);
-                GUILayout.FlexibleSpace();
-                EditorGUILayout.EndHorizontal();
+                if (_controller.PushProgress > 0)
+                {
+                    EditorGUILayout.LabelField(_controller.PushProgressMessage, EditorStyles.centeredGreyMiniLabel);
+                    var rect = EditorGUILayout.GetControlRect(false, 20);
+                    EditorGUI.ProgressBar(rect, _controller.PushProgress, $"{_controller.PushProgress:P0}");
+                }
+                else
+                {
+                    EditorGUILayout.BeginHorizontal();
+                    GUILayout.FlexibleSpace();
+                    GUILayout.Label(_controller.LoadingMessage, EditorStyles.largeLabel);
+                    GUILayout.FlexibleSpace();
+                    EditorGUILayout.EndHorizontal();
+                }
                 GUILayout.FlexibleSpace();
             }
             else if (_controller.Changes != null && _controller.Changes.Any())

+ 14 - 2
Assets/Arbitrator/Editor/Services/GitCommand.cs

@@ -27,20 +27,27 @@ namespace Terra.Arbitrator.Services
         /// Runs a git command asynchronously.
         /// </summary>
         /// <param name="log">A StringBuilder to capture command output for logging.</param>
+        /// <param name="progress">A delegate to report real-time standard error lines.</param>
         /// <param name="args">The arguments to pass to the git command.</param>
         /// <param name="acceptableExitCodes">A list of exit codes that should not be treated as errors.</param>
-        public static async Task RunAsync(StringBuilder log, string[] args, params int[] acceptableExitCodes)
+        public static async Task RunAsync(StringBuilder log, IProgress<string> progress, string[] args, params int[] acceptableExitCodes)
         {
             var stdOutBuffer = new StringBuilder();
             var stdErrBuffer = new StringBuilder();
             var argumentsString = string.Join(" ", args);
             log?.AppendLine($"\n--- Executing: git {argumentsString} ---");
+            
+            // Pipe stderr to a delegate that both captures the full output and reports each line for progress.
+            var stdErrPipe = PipeTarget.ToDelegate(line => {
+                stdErrBuffer.AppendLine(line);
+                progress?.Report(line); // Report progress for each line received.
+            });
 
             var command = Cli.Wrap(FindGitExecutable())
                              .WithArguments(args)
                              .WithWorkingDirectory(ProjectRoot)
                              .WithValidation(CommandResultValidation.None) // We handle validation manually
-                         | (PipeTarget.ToDelegate(x => stdOutBuffer.Append(x)), PipeTarget.ToDelegate(x => stdErrBuffer.Append(x)));
+                         | (PipeTarget.ToDelegate(x => stdOutBuffer.Append(x)), stdErrPipe);
 
             var result = await command.ExecuteAsync();
 
@@ -60,6 +67,11 @@ namespace Terra.Arbitrator.Services
             }
         }
         
+        public static Task RunAsync(StringBuilder log, string[] args, params int[] acceptableExitCodes)
+        {
+            return RunAsync(log, null, args, acceptableExitCodes);
+        }
+        
         /// <summary>
         /// Finds the absolute path to a given executable.
         /// </summary>

+ 24 - 2
Assets/Arbitrator/Editor/Services/GitExecutors.cs

@@ -11,6 +11,7 @@ using System.Linq;
 using UnityEngine;
 using LibGit2Sharp;
 using System.Text;
+using System.Globalization;
 using System.ComponentModel;
 using System.Threading.Tasks;
 using Terra.Arbitrator.Settings;
@@ -140,7 +141,7 @@ namespace Terra.Arbitrator.Services
             }
         }
         
-        public static async void CommitAndPushExecutor(Action<string> resolve, Action<Exception> reject, List<GitChange> changesToCommit, string commitMessage, string username, string email)
+        public static async void CommitAndPushExecutor(Action<string> resolve, Action<Exception> reject, List<GitChange> changesToCommit, string commitMessage, string username, string email, Action<float, string> onProgress)
         {
             try
             {
@@ -178,7 +179,8 @@ namespace Terra.Arbitrator.Services
                     repo.Commit(commitMessage, author, author);
                 }
 
-                await GitCommand.RunAsync(new StringBuilder(), new []{ "push" }, 0, 141);
+                var progressReporter = new Progress<string>(line => ParsePushProgress(line, onProgress));
+                await GitCommand.RunAsync(new StringBuilder(), progressReporter, new[] { "push", "--progress" }, 0, 141);
 
                 resolve("Successfully committed and pushed changes!");
             }
@@ -188,6 +190,26 @@ namespace Terra.Arbitrator.Services
                 reject(new Exception(errorMessage));
             }
         }
+        
+        private static void ParsePushProgress(string line, Action<float, string> onProgress)
+        {
+            if (onProgress == null || string.IsNullOrWhiteSpace(line)) return;
+
+            line = line.Trim();
+            var parts = line.Split(new[] { ':' }, 2);
+            if (parts.Length < 2) return;
+
+            var action = parts[0];
+            var progressPart = parts[1];
+            
+            var percentIndex = progressPart.IndexOf('%');
+            if (percentIndex == -1) return;
+
+            var percentString = progressPart.Substring(0, percentIndex).Trim();
+            if (!float.TryParse(percentString, NumberStyles.Any, CultureInfo.InvariantCulture, out var percentage)) return;
+            var progressValue = percentage / 100.0f;
+            onProgress(progressValue, $"{action}...");
+        }
 
         public static void ResetFileExecutor(Action<string> resolve, Action<Exception> reject, GitChange changeToReset)
         {

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

@@ -4,6 +4,7 @@
 // It creates promises and delegates the actual implementation work to the
 // internal GitExecutors class.
 
+using System;
 using Terra.Arbitrator.Promises;
 using Terra.Arbitrator.Settings;
 using System.Collections.Generic;
@@ -44,10 +45,10 @@ namespace Terra.Arbitrator.Services
         /// <summary>
         /// Commits and pushes the selected files to the remote repository.
         /// </summary>
-        public static IPromise<string> CommitAndPush(List<GitChange> changesToCommit, string commitMessage, string username, string email)
+        public static IPromise<string> CommitAndPush(List<GitChange> changesToCommit, string commitMessage, string username, string email, Action<float, string> onProgress = null)
         {
             return new Promise<string>((resolve, reject) => 
-                GitExecutors.CommitAndPushExecutor(resolve, reject, changesToCommit, commitMessage, username, email));
+                GitExecutors.CommitAndPushExecutor(resolve, reject, changesToCommit, commitMessage, username, email, onProgress));
         }
         
         /// <summary>