Browse Source

Sujith :) ->
1. Attempted to add support for prefab and scene diff

sujith 1 month ago
parent
commit
67f8e8b05d

+ 18 - 0
Assets/Arbitrator/Editor/GUI/ArbitratorController.cs

@@ -4,6 +4,7 @@
 // state and business logic, separating it from the UI rendering code in the window.
 
 using System;
+using GitMerge;
 using System.Linq;
 using UnityEditor;
 using Terra.Arbitrator.Settings;
@@ -154,8 +155,25 @@ namespace Terra.Arbitrator.GUI
         public void ResolveConflict(GitChange change)
         {
             if (IsLoading) return;
+            
             StartOperation($"Opening merge tool for {change.FilePath}...");
             
+            var fileExtension = System.IO.Path.GetExtension(change.FilePath).ToLower();
+            if (fileExtension is ".prefab" or ".unity")
+            {
+                try
+                {
+                    GitMergeWindow.ResolveConflict(change.FilePath);
+                }
+                catch (Exception e)
+                {
+                    ErrorMessage = e.Message;
+                }
+                
+                Refresh();
+                return;
+            }
+            
             GitService.LaunchMergeTool(change)
                 .Then(successMessage => { InfoMessage = successMessage; })
                 .Catch(HandleOperationError)

+ 22 - 17
Assets/Arbitrator/Editor/Services/GitExecutors.cs

@@ -174,27 +174,32 @@ namespace Terra.Arbitrator.Services
             {
                 using var repo = new Repository(ProjectRoot);
 
-                if (changeToReset.Status == ChangeKind.Added)
+                switch (changeToReset.Status)
                 {
-                    Commands.Unstage(repo, changeToReset.FilePath);
-                    
-                    var fullPath = Path.Combine(ProjectRoot, changeToReset.FilePath);
-                    if (File.Exists(fullPath))
+                    case ChangeKind.Added:
                     {
-                        File.Delete(fullPath);
+                        Commands.Unstage(repo, changeToReset.FilePath);
+                    
+                        var fullPath = Path.Combine(ProjectRoot, changeToReset.FilePath);
+                        if (File.Exists(fullPath))
+                        {
+                            File.Delete(fullPath);
+                        }
+
+                        break;
                     }
-                }
-                else if (changeToReset.Status == ChangeKind.Renamed)
-                {
-                    Commands.Unstage(repo, changeToReset.FilePath);
-                    var newFullPath = Path.Combine(ProjectRoot, changeToReset.FilePath);
-                    if (File.Exists(newFullPath)) File.Delete(newFullPath);
+                    case ChangeKind.Renamed:
+                    {
+                        Commands.Unstage(repo, changeToReset.FilePath);
+                        var newFullPath = Path.Combine(ProjectRoot, changeToReset.FilePath);
+                        if (File.Exists(newFullPath)) File.Delete(newFullPath);
                     
-                    repo.CheckoutPaths(repo.Head.Tip.Sha, new[] { changeToReset.OldFilePath }, new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });
-                }
-                else
-                {
-                    repo.CheckoutPaths(repo.Head.Tip.Sha, new[] { changeToReset.FilePath }, new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });
+                        repo.CheckoutPaths(repo.Head.Tip.Sha, new[] { changeToReset.OldFilePath }, new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });
+                        break;
+                    }
+                    default:
+                        repo.CheckoutPaths(repo.Head.Tip.Sha, new[] { changeToReset.FilePath }, new CheckoutOptions { CheckoutModifiers = CheckoutModifiers.Force });
+                        break;
                 }
 
                 resolve($"Successfully reset changes for '{changeToReset.FilePath}'");

+ 3 - 1
Assets/Arbitrator/Editor/Terra.Arbitrator.asmdef

@@ -1,7 +1,9 @@
 {
     "name": "Terra.Arbitrator",
     "rootNamespace": "Terra.Arbitrator",
-    "references": [],
+    "references": [
+        "GUID:13e5a9e99b20be54998e95b60302a730"
+    ],
     "includePlatforms": [
         "Editor"
     ],

+ 78 - 81
Assets/GitMerge/Editor/ConflictWatcher.cs

@@ -1,81 +1,78 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using UnityEditor;
-using UnityEngine;
-// Hello World
-// Hello World
-// Hello Here
-// Hello World
-namespace GitMerge
-{
-    public class ConflictWatcher
-    {
-        private static FileSystemWatcher watcher;
-        private static FileSystemEventArgs e;
-
-        public ConflictWatcher()
-        {
-            string assetPath = Application.dataPath;
-            watcher = new FileSystemWatcher(assetPath);
-            watcher.IncludeSubdirectories = true;
-            watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
-            watcher.Changed += OnFileChanged;
-            watcher.EnableRaisingEvents = true;
-        }
-
-        public event Action<string> OnConflict;
-
-        private void OnFileChanged(object sender, FileSystemEventArgs _e)
-        {
-            e = _e;
-            EditorApplication.update += CheckWindow;
-        }
-
-        private void CheckWindow()
-        {
-            AssetDatabase.Refresh();
-            EditorApplication.update -= CheckWindow;
-            var path = e.FullPath;
-            var relativePath = "Assets" + path.Substring(Application.dataPath.Length);
-
-            if (!path.EndsWith(".unity") && !path.EndsWith(".prefab")) return;
-            // Found it
-            UnityEngine.Object asset;
-            try
-            {
-                asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(relativePath);
-            }
-            catch (Exception exception)
-            {
-                Debug.Log(exception);
-                throw;
-            }
-            Debug.Log("asset" + asset);
-            if (asset != null)
-            {
-                Debug.Log("Found asset" + asset.GetType());
-                bool isBroken = asset is BrokenPrefabAsset;
-
-                // Open merge conflict window
-                if (isBroken)
-                {
-                    OnConflict?.Invoke(relativePath);
-                }
-            }
-        }
-
-        static bool IsOpenForEdit(string[] paths, List<string> outNotEditablePaths, StatusQueryOptions statusQueryOptions)
-        {
-            Debug.Log("IsOpenForEdit:");
-            // TODO: Do locking/unlocking here
-
-            foreach (var path in paths)
-            {
-                // Check for lock
-                Debug.Log(path);
-            }
-            return true;
-        }
-    }
-}
+// using System;
+// using System.Collections.Generic;
+// using System.IO;
+// using UnityEditor;
+// using UnityEngine;
+//
+// namespace GitMerge
+// {
+//     public class ConflictWatcher
+//     {
+//         private static FileSystemWatcher watcher;
+//         private static FileSystemEventArgs e;
+//
+//         public ConflictWatcher()
+//         {
+//             string assetPath = Application.dataPath;
+//             watcher = new FileSystemWatcher(assetPath);
+//             watcher.IncludeSubdirectories = true;
+//             watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
+//             watcher.Changed += OnFileChanged;
+//             watcher.EnableRaisingEvents = true;
+//         }
+//
+//         public event Action<string> OnConflict;
+//
+//         private void OnFileChanged(object sender, FileSystemEventArgs _e)
+//         {
+//             e = _e;
+//             EditorApplication.update += CheckWindow;
+//         }
+//
+//         private void CheckWindow()
+//         {
+//             AssetDatabase.Refresh();
+//             EditorApplication.update -= CheckWindow;
+//             var path = e.FullPath;
+//             var relativePath = "Assets" + path.Substring(Application.dataPath.Length);
+//
+//             if (!path.EndsWith(".unity") && !path.EndsWith(".prefab")) return;
+//             // Found it
+//             UnityEngine.Object asset;
+//             try
+//             {
+//                 asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(relativePath);
+//             }
+//             catch (Exception exception)
+//             {
+//                 Debug.Log(exception);
+//                 throw;
+//             }
+//             Debug.Log("asset" + asset);
+//             if (asset != null)
+//             {
+//                 Debug.Log("Found asset" + asset.GetType());
+//                 bool isBroken = asset is BrokenPrefabAsset;
+//
+//                 // Open merge conflict window
+//                 if (isBroken)
+//                 {
+//                     OnConflict?.Invoke(relativePath);
+//                 }
+//             }
+//         }
+//
+//         static bool IsOpenForEdit(string[] paths, List<string> outNotEditablePaths, StatusQueryOptions statusQueryOptions)
+//         {
+//             Debug.Log("IsOpenForEdit:");
+//             // TODO: Do locking/unlocking here
+//
+//             foreach (var path in paths)
+//             {
+//                 // Check for lock
+//                 Debug.Log(path);
+//             }
+//             return true;
+//         }
+//     }
+// }

+ 21 - 12
Assets/GitMerge/Editor/GitMergeWindow.cs

@@ -26,7 +26,6 @@ namespace GitMerge
 
         private MergeFilter filter = new MergeFilter();
         private MergeFilterBar filterBar = new MergeFilterBar();
-        private ConflictWatcher conflictWatcher = new ConflictWatcher();
 
         public bool mergeInProgress => mergeManager != null;
 
@@ -38,14 +37,30 @@ namespace GitMerge
         private Texture2D brokenLogo;
         private Texture2D fixedLogo;
         
-        [MenuItem("Window/GitMerge")]
-        static void OpenEditor()
+        private static void OpenEditor()
         {
-            var window = EditorWindow.GetWindow(typeof(GitMergeWindow), false, "GitMerge");
-            // In case we're merging and the scene becomes edited,
-            // the shown SerializedProperties should be repainted
+            GetWindow();
+        }
+
+        private static EditorWindow GetWindow()
+        {
+            var window = GetWindow(typeof(GitMergeWindow), false, "GitMerge");
             window.autoRepaintOnSceneChange = true;
             window.minSize = new Vector2(500, 100);
+            return window;
+        }
+
+        public static void ResolveConflict(string path)
+        {
+            if (path.Contains(".unity") || path.Contains(".prefab"))
+            {
+                var mergeWindow = GetWindow() as  GitMergeWindow;
+                if (mergeWindow != null)
+                {
+                    mergeWindow.InitializeMerge(path);
+                }
+            }
+            throw new NotSupportedException($"Cannot resolve conflict for: {path}");
         }
 
         private void OnEnable()
@@ -55,17 +70,11 @@ namespace GitMerge
             pageView.NumElementsPerPage = 200;
             filterBar.filter = filter;
             filter.OnChanged += CacheMergeActions;
-            conflictWatcher.OnConflict += InitializeMerge;
             Selection.selectionChanged += Repaint;
             EditorApplication.hierarchyWindowItemOnGUI += HighlightItems;
             LoadSettings();
         }
 
-        private void OnDisable()
-        {
-            conflictWatcher.OnConflict -= InitializeMerge;
-        }
-
         private static void LoadSettings()
         {
             automerge = EditorPrefs.GetBool(EDITOR_PREFS_AUTOMERGE, true);

+ 8 - 0
Assets/Prefabs.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: c718d135ac69842f79de5061a6bacb51
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 110 - 0
Assets/Prefabs/Sphere.prefab

@@ -0,0 +1,110 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!1 &254937477822833254
+GameObject:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  serializedVersion: 6
+  m_Component:
+  - component: {fileID: 1917423583392372291}
+  - component: {fileID: 6488191159553717518}
+  - component: {fileID: 3320614929064822560}
+  - component: {fileID: 5600940220632148680}
+  m_Layer: 0
+  m_Name: Sphere
+  m_TagString: Untagged
+  m_Icon: {fileID: 0}
+  m_NavMeshLayer: 0
+  m_StaticEditorFlags: 0
+  m_IsActive: 1
+--- !u!4 &1917423583392372291
+Transform:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 254937477822833254}
+  serializedVersion: 2
+  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+  m_LocalPosition: {x: 0, y: 0, z: 0}
+  m_LocalScale: {x: 1, y: 1, z: 1}
+  m_ConstrainProportionsScale: 1
+  m_Children: []
+  m_Father: {fileID: 0}
+  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!33 &6488191159553717518
+MeshFilter:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 254937477822833254}
+  m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
+--- !u!23 &3320614929064822560
+MeshRenderer:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 254937477822833254}
+  m_Enabled: 1
+  m_CastShadows: 1
+  m_ReceiveShadows: 1
+  m_DynamicOccludee: 1
+  m_StaticShadowCaster: 0
+  m_MotionVectors: 1
+  m_LightProbeUsage: 1
+  m_ReflectionProbeUsage: 1
+  m_RayTracingMode: 2
+  m_RayTraceProcedural: 0
+  m_RayTracingAccelStructBuildFlagsOverride: 0
+  m_RayTracingAccelStructBuildFlags: 1
+  m_SmallMeshCulling: 1
+  m_RenderingLayerMask: 1
+  m_RendererPriority: 0
+  m_Materials:
+  - {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
+  m_StaticBatchInfo:
+    firstSubMesh: 0
+    subMeshCount: 0
+  m_StaticBatchRoot: {fileID: 0}
+  m_ProbeAnchor: {fileID: 0}
+  m_LightProbeVolumeOverride: {fileID: 0}
+  m_ScaleInLightmap: 1
+  m_ReceiveGI: 1
+  m_PreserveUVs: 0
+  m_IgnoreNormalsForChartDetection: 0
+  m_ImportantGI: 0
+  m_StitchLightmapSeams: 1
+  m_SelectedEditorRenderState: 3
+  m_MinimumChartSize: 4
+  m_AutoUVMaxDistance: 0.5
+  m_AutoUVMaxAngle: 89
+  m_LightmapParameters: {fileID: 0}
+  m_SortingLayerID: 0
+  m_SortingLayer: 0
+  m_SortingOrder: 0
+  m_AdditionalVertexStreams: {fileID: 0}
+--- !u!135 &5600940220632148680
+SphereCollider:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 254937477822833254}
+  m_Material: {fileID: 0}
+  m_IncludeLayers:
+    serializedVersion: 2
+    m_Bits: 0
+  m_ExcludeLayers:
+    serializedVersion: 2
+    m_Bits: 0
+  m_LayerOverridePriority: 0
+  m_IsTrigger: 0
+  m_ProvidesContacts: 0
+  m_Enabled: 1
+  serializedVersion: 3
+  m_Radius: 0.5
+  m_Center: {x: 0, y: 0, z: 0}

+ 7 - 0
Assets/Prefabs/Sphere.prefab.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0
+PrefabImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 58 - 0
Assets/Scenes/SampleScene.unity

@@ -426,6 +426,63 @@ Transform:
   m_Children: []
   m_Father: {fileID: 0}
   m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+--- !u!1001 &4749853077889977857
+PrefabInstance:
+  m_ObjectHideFlags: 0
+  serializedVersion: 2
+  m_Modification:
+    serializedVersion: 3
+    m_TransformParent: {fileID: 0}
+    m_Modifications:
+    - target: {fileID: 254937477822833254, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_Name
+      value: Sphere
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalPosition.x
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalPosition.y
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalPosition.z
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalRotation.w
+      value: 1
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalRotation.x
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalRotation.y
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalRotation.z
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalEulerAnglesHint.x
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalEulerAnglesHint.y
+      value: 0
+      objectReference: {fileID: 0}
+    - target: {fileID: 1917423583392372291, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
+      propertyPath: m_LocalEulerAnglesHint.z
+      value: 0
+      objectReference: {fileID: 0}
+    m_RemovedComponents: []
+    m_RemovedGameObjects: []
+    m_AddedGameObjects: []
+    m_AddedComponents: []
+  m_SourcePrefab: {fileID: 100100000, guid: 20ea0bfd22b354d0fbe4e2c4e2ae2ef0, type: 3}
 --- !u!1660057539 &9223372036854775807
 SceneRoots:
   m_ObjectHideFlags: 0
@@ -433,3 +490,4 @@ SceneRoots:
   - {fileID: 330585546}
   - {fileID: 410087041}
   - {fileID: 832575519}
+  - {fileID: 4749853077889977857}