Browse Source

Sujith :) ->
1. Fixed reset multiple files flow
2. Removed better git persistence

sujith 1 month ago
parent
commit
38a4bab586

+ 19 - 50
Assets/Better Git/Arbitrator/Editor/GUI/ArbitratorController.cs

@@ -56,16 +56,7 @@ namespace Terra.Arbitrator.GUI
         
         public void OnEnable()
         {
-            if (SessionState.GetBool(BetterGitStatePersistence.ResetQueueKey, false))
-            {
-                SessionState.EraseString(BetterGitStatePersistence.ResetQueueKey);
-                InfoMessage = "Multi-file reset complete. Pulling again to confirm...";
-                Pull();
-            }
-            else
-            {
-                Refresh();
-            }
+            Refresh();
         }
 
         public void Refresh()
@@ -406,57 +397,35 @@ namespace Terra.Arbitrator.GUI
 
         private void ResetMultipleFiles(List<string> filePaths)
         {
-            var hasScripts = filePaths.Any(p => p.EndsWith(".cs", StringComparison.OrdinalIgnoreCase));
-
-            if (hasScripts)
-            {
-                InfoMessage = $"Starting reset for {filePaths.Count} file(s)... This may trigger script compilation.";
-                _requestRepaint?.Invoke();
-                SessionState.SetString("BetterGit.ResetQueue", string.Join(";", filePaths));
-                EditorApplication.delayCall += BetterGitStatePersistence.ContinueInterruptedReset;
-            }
-            else
-            {
-                StartOperation($"Resetting {filePaths.Count} file(s)...");
+            EditorApplication.LockReloadAssemblies();
+            StartOperation($"Resetting {filePaths.Count} file(s)...");
 
-                IPromise<string> promiseChain = new Promise<string>((resolve, _) => resolve(""));
+            IPromise<string> promiseChain = new Promise<string>((resolve, _) => resolve(""));
 
-                foreach (var path in filePaths)
+            foreach (var path in filePaths)
+            {
+                promiseChain = promiseChain.Then(_ =>
                 {
-                    promiseChain = promiseChain.Then(_ => {
-                        var change = GitService.GetChangeForFile(path);
-                        return change != null ? GitService.ResetFileChanges(change) : new Promise<string>((res, _) => res(""));
-                    });
-                }
-
-                promiseChain
-                    .Then(successMsg => {
-                        InfoMessage = $"Successfully reset {filePaths.Count} file(s).";
-                        Refresh();
-                    })
-                    .Catch(ex => {
-                        HandleOperationError(ex);
-                        FinishOperation();
-                    });
+                    var change = GitService.GetChangeForFile(path);
+                    return change != null ? GitService.ResetFileChanges(change) : new Promise<string>((res, _) => res(""));
+                });
             }
-        }
-        
-        public void ForcePull()
-        {
-            StartOperation("Attempting to pull and create conflicts...");
-            
-            EditorApplication.LockReloadAssemblies();
-            GitService.ForcePull()
+
+            promiseChain
                 .Then(_ =>
                 {
-                    InfoMessage = "Pull resulted in conflicts. Please resolve them below.";
+                    InfoMessage = $"Successfully reset {filePaths.Count} file(s).";
+                    Refresh();
+                })
+                .Catch(ex =>
+                {
+                    HandleOperationError(ex);
+                    FinishOperation();
                 })
-                .Catch(HandleOperationError)
                 .Finally(() =>
                 {
                     EditorApplication.UnlockReloadAssemblies();
                     AssetDatabase.Refresh();
-                    Refresh();
                 });
         }
         

+ 0 - 75
Assets/Better Git/Arbitrator/Editor/Services/BetterGitStatePersistence.cs

@@ -1,75 +0,0 @@
-// Copyright (c) 2025 TerraByte Inc.
-//
-// A static class that persists the state of a multi-file reset operation
-// across script re-compilations, ensuring the process is not interrupted.
-
-using System.Linq;
-using UnityEditor;
-using UnityEngine.Scripting;
-
-namespace Terra.Arbitrator.Services
-{
-    [Preserve]
-    [InitializeOnLoad]
-    public static class BetterGitStatePersistence
-    {
-        internal const string ResetQueueKey = "BetterGit.ResetQueue";
-
-        // This static constructor runs automatically after every script compilation.
-        static BetterGitStatePersistence()
-        {
-            // Use delayCall to ensure this runs after the editor is fully initialized.
-            EditorApplication.delayCall += ContinueInterruptedReset;
-        }
-
-        public static void ContinueInterruptedReset()
-        {
-            while (true)
-            {
-                var queuedFiles = SessionState.GetString(ResetQueueKey, "");
-                if (string.IsNullOrEmpty(queuedFiles))
-                {
-                    return; // Nothing to do.
-                }
-
-                var fileList = queuedFiles.Split(';').ToList();
-                if (!fileList.Any())
-                {
-                    SessionState.EraseString(ResetQueueKey);
-                    return;
-                }
-
-                // Get the next file to process
-                var fileToReset = fileList.First();
-                fileList.RemoveAt(0);
-
-                // Update the session state with the remaining files BEFORE starting the operation.
-                if (fileList.Any())
-                {
-                    SessionState.SetString(ResetQueueKey, string.Join(";", fileList));
-                }
-                else
-                {
-                    // Last file was processed, clear the key.
-                    SessionState.EraseString(ResetQueueKey);
-                }
-
-                // Create a GitChange object for the file to be reset.
-                // This is a small, synchronous operation to get the file's current status.
-                var change = GitService.GetChangeForFile(fileToReset);
-                if (change == null)
-                {
-                    // The File might have already been reset or state is unusual.
-                    // We'll log it and attempt to continue.
-                    UnityEngine.Debug.LogWarning($"Could not find status for {fileToReset}, skipping reset. It may have already been processed.");
-                    continue;
-                }
-
-                // Trigger the reset. After this, Unity will recompile if it was a script,
-                // and this whole static constructor will run again.
-                GitService.ResetFileChanges(change);
-                break;
-            }
-        }
-    }
-}

+ 0 - 3
Assets/Better Git/Arbitrator/Editor/Services/BetterGitStatePersistence.cs.meta

@@ -1,3 +0,0 @@
-fileFormatVersion: 2
-guid: deefd0d04b804e368c5bd45a1802d698
-timeCreated: 1750678265