-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityMerge.cs
More file actions
65 lines (57 loc) · 2.52 KB
/
UnityMerge.cs
File metadata and controls
65 lines (57 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System;
namespace GitIntegration
{
[InitializeOnLoad]
public class SmartMergeRegistrator
{
const string SmartMergeRegistratorEditorPrefsKey = "smart_merge_installed";
const int Version = 1;
static string VersionKey = $"{Version}_{Application.unityVersion}";
public static string ExecuteGitWithParams(string param)
{
var processInfo = new System.Diagnostics.ProcessStartInfo("git");
processInfo.UseShellExecute = false;
processInfo.WorkingDirectory = Environment.CurrentDirectory;
processInfo.RedirectStandardOutput = true;
processInfo.RedirectStandardError = true;
processInfo.CreateNoWindow = true;
var process = new System.Diagnostics.Process();
process.StartInfo = processInfo;
process.StartInfo.FileName = "git";
process.StartInfo.Arguments = param;
process.Start();
process.WaitForExit();
if (process.ExitCode != 0)
throw new Exception(process.StandardError.ReadLine());
return process.StandardOutput.ReadLine();
}
[MenuItem("Tools/Git/SmartMerge registration")]
static void SmartMergeRegister()
{
try
{
var UnityYAMLMergePath = EditorApplication.applicationContentsPath + "/Tools" + "/UnityYAMLMerge.exe";
ExecuteGitWithParams("config merge.unityyamlmerge.name \"Unity SmartMerge (UnityYamlMerge)\"");
ExecuteGitWithParams($"config merge.unityyamlmerge.driver \"\\\"{UnityYAMLMergePath}\\\" merge -h -p --force --fallback none %O %B %A %A\"");
ExecuteGitWithParams("config merge.unityyamlmerge.recursive binary");
EditorPrefs.SetString(SmartMergeRegistratorEditorPrefsKey, VersionKey);
Debug.Log($"Succesfuly registered UnityYAMLMerge with path {UnityYAMLMergePath}");
}
catch (Exception e)
{
Debug.Log($"Fail to register UnityYAMLMerge with error: {e}");
}
}
//Unity calls the static constructor when the engine opens
static SmartMergeRegistrator()
{
var instaledVersionKey = EditorPrefs.GetString(SmartMergeRegistratorEditorPrefsKey);
if (instaledVersionKey != VersionKey)
SmartMergeRegister();
}
}
}
#endif