From 70222ac5b5f64c954c4b977605b74497476a255f Mon Sep 17 00:00:00 2001
From: Shutong Wu <51266340+Scriptwonder@users.noreply.github.com>
Date: Wed, 2 Sep 2026 20:01:27 -0400
Subject: [PATCH 1/2] feat(setup): show git status in the setup window and
explain the Git-URL failure
Adding the package from a Git URL makes the Package Manager shell out to git, and
two failures look identical to the user: git missing from PATH, or git refusing a
folder owned by another account ('fatal: not in a git directory'). Issue #1216 and
its duplicates are all one of those two, and the setup window gave no signal either
way because it only checks Python and uv.
Detect git as an OPTIONAL dependency so a missing git can never block setup, show
it as its own row, and put the safe.directory remedy in the row details and in the
troubleshooting guide. Missing optional dependencies now render in the neutral
colour rather than the red reserved for required ones.
Closes #1216
---
.../Editor/Dependencies/DependencyManager.cs | 3 +
.../PlatformDetectors/IPlatformDetector.cs | 5 ++
.../PlatformDetectors/PlatformDetectorBase.cs | 61 +++++++++++++++++
MCPForUnity/Editor/Windows/MCPSetupWindow.cs | 21 +++++-
.../Editor/Windows/MCPSetupWindow.uxml | 12 +++-
.../Tests/EditMode/GitDetectionTests.cs | 66 +++++++++++++++++++
.../Tests/EditMode/GitDetectionTests.cs.meta | 11 ++++
website/docs/getting-started/install.md | 2 +
website/docs/guides/troubleshooting.md | 17 +++++
9 files changed, 195 insertions(+), 3 deletions(-)
create mode 100644 TestProjects/UnityMCPTests/Assets/Tests/EditMode/GitDetectionTests.cs
create mode 100644 TestProjects/UnityMCPTests/Assets/Tests/EditMode/GitDetectionTests.cs.meta
diff --git a/MCPForUnity/Editor/Dependencies/DependencyManager.cs b/MCPForUnity/Editor/Dependencies/DependencyManager.cs
index c3802c475..79c4156e0 100644
--- a/MCPForUnity/Editor/Dependencies/DependencyManager.cs
+++ b/MCPForUnity/Editor/Dependencies/DependencyManager.cs
@@ -60,6 +60,9 @@ public static DependencyCheckResult CheckAllDependencies()
var uvStatus = detector.DetectUv();
result.Dependencies.Add(uvStatus);
+ // Check git (optional: Package Manager Git-URL installs only)
+ result.Dependencies.Add(detector.DetectGit());
+
// Generate summary and recommendations
result.GenerateSummary();
GenerateRecommendations(result, detector);
diff --git a/MCPForUnity/Editor/Dependencies/PlatformDetectors/IPlatformDetector.cs b/MCPForUnity/Editor/Dependencies/PlatformDetectors/IPlatformDetector.cs
index 3231105e9..08a3c221e 100644
--- a/MCPForUnity/Editor/Dependencies/PlatformDetectors/IPlatformDetector.cs
+++ b/MCPForUnity/Editor/Dependencies/PlatformDetectors/IPlatformDetector.cs
@@ -27,6 +27,11 @@ public interface IPlatformDetector
///
DependencyStatus DetectUv();
+ ///
+ /// Detect git on this platform. Optional: only the Package Manager's Git-URL install path needs it.
+ ///
+ DependencyStatus DetectGit();
+
///
/// Get platform-specific installation recommendations
///
diff --git a/MCPForUnity/Editor/Dependencies/PlatformDetectors/PlatformDetectorBase.cs b/MCPForUnity/Editor/Dependencies/PlatformDetectors/PlatformDetectorBase.cs
index c955381d1..73693f2a4 100644
--- a/MCPForUnity/Editor/Dependencies/PlatformDetectors/PlatformDetectorBase.cs
+++ b/MCPForUnity/Editor/Dependencies/PlatformDetectors/PlatformDetectorBase.cs
@@ -64,6 +64,67 @@ public virtual DependencyStatus DetectUv()
}
+ // Git is not needed to run the bridge, only to add or update the package from a Git URL
+ // in the Package Manager, which is the install path most users take (issue #1216). It is
+ // reported as optional so a missing git never blocks setup, but the row tells the user why
+ // "Error when executing git command" appeared and how to clear it.
+ public const string GitInstallUrl = "https://git-scm.com/downloads";
+
+ public virtual DependencyStatus DetectGit()
+ {
+ var status = new DependencyStatus("Git", isRequired: false)
+ {
+ InstallationHint = GitInstallUrl
+ };
+
+ try
+ {
+ if (!TryFindInPath("git", out string gitPath))
+ {
+ status.ErrorMessage = "git not found";
+ status.Details = "Only needed to add or update MCP for Unity from a Git URL in the Package Manager.";
+ return status;
+ }
+
+ if (ExecPath.TryRun(gitPath, "--version", null, out string stdout, out string stderr, 5000)
+ && TryParseGitVersion(string.IsNullOrWhiteSpace(stdout) ? stderr : stdout, out string version))
+ {
+ status.IsAvailable = true;
+ status.Version = version;
+ status.Path = gitPath;
+ status.Details = "If the Package Manager still reports 'not in a git directory', git is refusing a folder "
+ + "owned by another user: run git config --global --add safe.directory ";
+ return status;
+ }
+
+ status.ErrorMessage = "git found but did not report a version";
+ status.Path = gitPath;
+ }
+ catch (Exception ex)
+ {
+ status.ErrorMessage = $"Error detecting git: {ex.Message}";
+ }
+
+ return status;
+ }
+
+ /// Parses "git version 2.45.1.windows.1" or "git version 2.39.5 (Apple Git-154)" into "2.45.1.windows.1" / "2.39.5".
+ internal static bool TryParseGitVersion(string output, out string version)
+ {
+ version = null;
+ string line = (output ?? string.Empty).Trim();
+ const string prefix = "git version ";
+ if (!line.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
+ {
+ return false;
+ }
+
+ string rest = line.Substring(prefix.Length).Trim();
+ int end = rest.IndexOfAny(new[] { ' ', '\r', '\n' });
+ version = end >= 0 ? rest.Substring(0, end) : rest;
+ return version.Length > 0 && char.IsDigit(version[0]);
+ }
+
protected bool TryParseVersion(string version, out int major, out int minor)
{
major = 0;
diff --git a/MCPForUnity/Editor/Windows/MCPSetupWindow.cs b/MCPForUnity/Editor/Windows/MCPSetupWindow.cs
index efbee14e8..d8ee58879 100644
--- a/MCPForUnity/Editor/Windows/MCPSetupWindow.cs
+++ b/MCPForUnity/Editor/Windows/MCPSetupWindow.cs
@@ -25,6 +25,9 @@ public class MCPSetupWindow : EditorWindow
private VisualElement uvIndicator;
private Label uvVersion;
private Label uvDetails;
+ private VisualElement gitIndicator;
+ private Label gitVersion;
+ private Label gitDetails;
private Label statusMessage;
private VisualElement installationSection;
private Label installationInstructions;
@@ -88,6 +91,9 @@ public void CreateGUI()
uvIndicator = rootVisualElement.Q("uv-indicator");
uvVersion = rootVisualElement.Q