fix: crash issues on push

This commit is contained in:
2026-05-05 19:43:54 +02:00
parent e89eb856ca
commit a3a23902ab
+60 -9
View File
@@ -37,6 +37,9 @@ public class GitPanel : EditorWindow
private double lastRefreshTime = -999; private double lastRefreshTime = -999;
private bool isLoading = false;
private string loadingMessage = "";
private struct CommitInfo { public string hash; public string date; public string message; } private struct CommitInfo { public string hash; public string date; public string message; }
private List<CommitInfo> commitHistory = new List<CommitInfo>(); private List<CommitInfo> commitHistory = new List<CommitInfo>();
@@ -49,11 +52,41 @@ public class GitPanel : EditorWindow
private void OnEnable() private void OnEnable()
{ {
EditorApplication.update += OnEditorUpdate;
prefsKey = $"GitTool_WebUrl_{Application.dataPath.GetHashCode()}"; prefsKey = $"GitTool_WebUrl_{Application.dataPath.GetHashCode()}";
webUrlOverride = EditorPrefs.GetString(prefsKey, ""); webUrlOverride = EditorPrefs.GetString(prefsKey, "");
RefreshData(); RefreshData();
} }
private void OnDisable()
{
EditorApplication.update -= OnEditorUpdate;
}
private void OnEditorUpdate()
{
if (isLoading) Repaint();
}
private void RunNetworkCommand(string message, System.Func<string> work, System.Action<string> onDone)
{
if (isLoading) return;
isLoading = true;
loadingMessage = message;
Repaint();
System.Threading.ThreadPool.QueueUserWorkItem(_ =>
{
string result = work();
EditorApplication.delayCall += () =>
{
isLoading = false;
loadingMessage = "";
onDone(result);
Repaint();
};
});
}
private void OnFocus() private void OnFocus()
{ {
if (EditorApplication.timeSinceStartup - lastRefreshTime > 2.0) if (EditorApplication.timeSinceStartup - lastRefreshTime > 2.0)
@@ -123,6 +156,21 @@ public class GitPanel : EditorWindow
private void OnGUI() private void OnGUI()
{ {
if (isLoading)
{
EditorGUI.DrawRect(new Rect(0, 0, position.width, position.height), new Color(0.15f, 0.15f, 0.15f, 1f));
string[] frames = { "|", "/", "-", "\\" };
string spinner = frames[(int)(EditorApplication.timeSinceStartup * 8) % 4];
GUIStyle style = new GUIStyle(EditorStyles.boldLabel)
{
alignment = TextAnchor.MiddleCenter,
fontSize = 13,
normal = { textColor = Color.white }
};
GUI.Label(new Rect(0, position.height / 2 - 20, position.width, 40), $"{spinner} {loadingMessage}", style);
return;
}
GUILayout.Space(10); GUILayout.Space(10);
GUILayout.Label("GIT Version Control System", EditorStyles.boldLabel); GUILayout.Label("GIT Version Control System", EditorStyles.boldLabel);
if (hasRepo) GUILayout.Label($"Active Branch: {currentBranchName}", EditorStyles.miniLabel); if (hasRepo) GUILayout.Label($"Active Branch: {currentBranchName}", EditorStyles.miniLabel);
@@ -245,7 +293,6 @@ public class GitPanel : EditorWindow
GUI.backgroundColor = new Color(0.2f, 0.4f, 0.8f); GUI.backgroundColor = new Color(0.2f, 0.4f, 0.8f);
if (GUILayout.Button("✓ Push", GUILayout.Height(30))) if (GUILayout.Button("✓ Push", GUILayout.Height(30)))
{ {
UnityEngine.Debug.Log("Git-Tool: Saving Scenes and Assets before push...");
UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes(); UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
@@ -254,17 +301,19 @@ public class GitPanel : EditorWindow
RunGitCommand("add .", true); RunGitCommand("add .", true);
RunGitCommand($"commit -m \"{commitMessage}\"", true); RunGitCommand($"commit -m \"{commitMessage}\"", true);
string pushResult = RunGitCommand("push -u origin HEAD", true, 60000); RunNetworkCommand("Pushing to remote... (a browser window may open for authentication)",
if (pushResult.Contains("rejected") || pushResult.Contains("fetch first")) () => RunGitCommand("push -u origin HEAD", true, 180000),
result =>
{ {
if (result.Contains("rejected") || result.Contains("fetch first"))
UnityEngine.Debug.LogError("Git-Tool: PUSH REJECTED! Someone else pushed changes. Please click 'Pull' first."); UnityEngine.Debug.LogError("Git-Tool: PUSH REJECTED! Someone else pushed changes. Please click 'Pull' first.");
}
else else
{ {
UnityEngine.Debug.Log("Git-Tool: Changes successfully pushed!"); UnityEngine.Debug.Log("Git-Tool: Changes successfully pushed!");
commitMessage = ""; commitMessage = "";
} }
RefreshData(); RefreshData();
});
} }
GUI.backgroundColor = new Color(0.8f, 0.6f, 0.2f); GUI.backgroundColor = new Color(0.8f, 0.6f, 0.2f);
@@ -273,15 +322,18 @@ public class GitPanel : EditorWindow
UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes(); UnityEditor.SceneManagement.EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
string pullResult = RunGitCommand("pull", true, 60000); RunNetworkCommand("Pulling from remote... (a browser window may open for authentication)",
() => RunGitCommand("pull", true, 180000),
result =>
{
AssetDatabase.Refresh(); AssetDatabase.Refresh();
if (result.Contains("CONFLICT"))
if (pullResult.Contains("CONFLICT"))
{ {
UnityEngine.Debug.LogError("Git-Tool: MERGE CONFLICT! Please resolve conflicts in your code editor."); UnityEngine.Debug.LogError("Git-Tool: MERGE CONFLICT! Please resolve conflicts in your code editor.");
EditorUtility.DisplayDialog("Merge Conflict", "There are conflicts with the remote changes.\n\nGit could not merge automatically. Please open the conflicting files in your code editor and resolve them manually.", "OK"); EditorUtility.DisplayDialog("Merge Conflict", "There are conflicts with the remote changes.\n\nGit could not merge automatically. Please open the conflicting files in your code editor and resolve them manually.", "OK");
} }
RefreshData(); RefreshData();
});
} }
GUI.backgroundColor = new Color(0.8f, 0.3f, 0.3f); GUI.backgroundColor = new Color(0.8f, 0.3f, 0.3f);
@@ -551,9 +603,8 @@ public class GitPanel : EditorWindow
RedirectStandardError = true, RedirectStandardError = true,
CreateNoWindow = true CreateNoWindow = true
}; };
// Prevent Git from waiting for credential/SSH prompts that can never appear // Block stdin credential prompts (no TTY in Unity), but allow GCM browser/GUI auth
si.EnvironmentVariables["GIT_TERMINAL_PROMPT"] = "0"; si.EnvironmentVariables["GIT_TERMINAL_PROMPT"] = "0";
si.EnvironmentVariables["GCM_INTERACTIVE"] = "never";
si.EnvironmentVariables["GIT_SSH_COMMAND"] = "ssh -o BatchMode=yes -o ConnectTimeout=15"; si.EnvironmentVariables["GIT_SSH_COMMAND"] = "ssh -o BatchMode=yes -o ConnectTimeout=15";
var stdout = new System.Text.StringBuilder(); var stdout = new System.Text.StringBuilder();