Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio installer: do not run Apple's git shim to ask whether git works (#11759)

Daniel Han0fc6f172254e
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index 8867c562852..e2c5b9e8cd2 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -9523,6 +9523,51 @@ def patch_package_file(package_name: str, relative_path: str, url: str) -> None:
# -- Main install sequence ---------------------------------------------
+# Apple's Command Line Tools shim, which pops a GUI install dialog when run without a toolchain.
+_CLT_GIT_SHIM = "/usr/bin/git"
+
+
+def _apple_silicon_hardware() -> bool:
+ """Whether the MACHINE is Apple Silicon, even when this Python runs under Rosetta.
+
+ install.sh's _MAC_ROSETTA: an x86_64 shell on an arm64 Mac reports x86_64, while
+ hw.optional.arm64 stays 1. Intel Macs keep probing /usr/bin/git by running it, as install.sh
+ does, because a CI Intel image ships a working one there.
+ """
+ if not IS_MACOS:
+ return False
+ if platform.machine() == "arm64":
+ return True
+ try:
+ answer = subprocess.run(
+ ["sysctl", "-in", "hw.optional.arm64"],
+ capture_output = True,
+ text = True,
+ timeout = 10,
+ ).stdout
+ except (OSError, subprocess.SubprocessError):
+ return False
+ return answer.strip() == "1"
+
+
+def _is_unarmed_clt_git_shim(exe: str) -> bool:
+ """`exe` is Apple Silicon's /usr/bin/git shim and `xcode-select -p` names no toolchain."""
+ if exe != _CLT_GIT_SHIM or not _apple_silicon_hardware():
+ return False
+ try:
+ return (
+ subprocess.run(
+ ["xcode-select", "-p"],
+ stdout = subprocess.DEVNULL,
+ stderr = subprocess.DEVNULL,
+ timeout = 30,
+ ).returncode
+ != 0
+ )
+ except (OSError, subprocess.SubprocessError):
+ return True
+
+
def _has_working_git() -> bool:
"""Match install.sh's _has_working_git: on PATH *and* actually runnable.
@@ -9533,6 +9578,12 @@ def _has_working_git() -> bool:
exe = shutil.which("git")
if exe is None:
return False
+ # Without the Command Line Tools, Apple Silicon's /usr/bin/git is Apple's shim, and running it
+ # raises the "install the command line developer tools" dialog: the probe would fire the very
+ # prompt it exists to avoid. Answer from the path, as install.sh does. Only that exact shim with
+ # no toolchain selected; a Homebrew or Xcode.app git is real and is still run.
+ if _is_unarmed_clt_git_shim(exe):
+ return False
try:
return (
subprocess.run(
diff --git a/tests/studio/install/test_git_probe_clt_shim.py b/tests/studio/install/test_git_probe_clt_shim.py
new file mode 100644
index 00000000000..94ff1d06e2a
--- /dev/null
+++ b/tests/studio/install/test_git_probe_clt_shim.py
@@ -0,0 +1,142 @@
+"""install_python_stack's git probe never runs Apple's Command Line Tools shim.
+
+Without the CLT, Apple Silicon's /usr/bin/git is a shim, and running it (even `git --version`)
+raises the "install the command line developer tools" dialog. install.sh's _has_working_git
+answers from the path there. The Python probe ran `git --version` unconditionally, which was
+harmless while only the triton step (skipped on macOS) asked. Since the pinned Diffusers main
+build became the default, every macOS install asks, so a Mac without the CLT got the dialog in
+the middle of the install.
+
+Every call the probe makes goes through a stand-in `subprocess.run` here, so each row records
+whether git itself would have been executed.
+"""
+
+from __future__ import annotations
+
+import importlib.util
+import pathlib
+import subprocess
+import sys
+import types
+
+import pytest
+
+REPO_ROOT = pathlib.Path(__file__).resolve().parents[3]
+STACK_PATH = REPO_ROOT / "studio" / "install_python_stack.py"
+
+
+def _load():
+ sys.path.insert(0, str(REPO_ROOT / "studio"))
+ try:
+ spec = importlib.util.spec_from_file_location("studio_stack_git_probe", STACK_PATH)
+ module = importlib.util.module_from_spec(spec)
+ sys.modules[spec.name] = module
+ spec.loader.exec_module(module)
+ finally:
+ if sys.path and sys.path[0] == str(REPO_ROOT / "studio"):
+ sys.path.pop(0)
+ return module
+
+
+stack = _load()
+
+
+def _probe(monkeypatch, *, macos, machine, arm64_sysctl, git, toolchain):
+ """Run _has_working_git on a described host; return (answer, commands run)."""
+ ran: list[list[str]] = []
+
+ def fake_run(cmd, *args, **kwargs):
+ ran.append(list(cmd))
+ name = pathlib.PurePosixPath(cmd[0]).name
+ if name == "sysctl":
+ return types.SimpleNamespace(returncode = 0, stdout = arm64_sysctl + "\n")
+ if name == "xcode-select":
+ return types.SimpleNamespace(returncode = 0 if toolchain else 2, stdout = "")
+ if name == "git":
+ return types.SimpleNamespace(returncode = 0, stdout = "")
+ raise AssertionError(f"unexpected command {cmd}")
+
+ monkeypatch.setattr(stack, "IS_MACOS", macos)
+ monkeypatch.setattr(stack.platform, "machine", lambda: machine)
+ monkeypatch.setattr(stack.shutil, "which", lambda name: git if name == "git" else None)
+ monkeypatch.setattr(stack.subprocess, "run", fake_run)
+ return stack._has_working_git(), ran
+
+
+def _ran_git(ran):
+ return any(pathlib.PurePosixPath(cmd[0]).name == "git" for cmd in ran)
+
+
+ "machine, arm64_sysctl",
+ [
+ pytest.param("arm64", "1", id = "apple-silicon"),
+ pytest.param("x86_64", "1", id = "apple-silicon-under-rosetta"),
+ ],
+)
+def test_the_clt_shim_is_not_run_without_a_toolchain(monkeypatch, machine, arm64_sysctl):
+ answer, ran = _probe(
+ monkeypatch,
+ macos = True,
+ machine = machine,
+ arm64_sysctl = arm64_sysctl,
+ git = "/usr/bin/git",
+ toolchain = False,
+ )
+ assert answer is False
+ assert not _ran_git(ran), f"the probe ran Apple's git shim, which raises the dialog: {ran}"
+ assert ["xcode-select", "-p"] in ran
+
+
+ "macos, machine, arm64_sysctl, git, toolchain",
+ [
+ pytest.param(True, "arm64", "1", "/usr/bin/git", True, id = "shim-with-clt-installed"),
+ pytest.param(True, "arm64", "1", "/opt/homebrew/bin/git", False, id = "homebrew-git"),
+ pytest.param(True, "x86_64", "0", "/usr/bin/git", False, id = "intel-mac"),
+ pytest.param(False, "x86_64", "0", "/usr/bin/git", False, id = "linux"),
+ ],
+)
+def test_every_other_git_is_still_run(monkeypatch, macos, machine, arm64_sysctl, git, toolchain):
+ answer, ran = _probe(
+ monkeypatch,
+ macos = macos,
+ machine = machine,
+ arm64_sysctl = arm64_sysctl,
+ git = git,
+ toolchain = toolchain,
+ )
+ assert answer is True
+ assert [git, "--version"] in ran
+
+
+def test_linux_never_asks_the_mac_questions(monkeypatch):
+ _, ran = _probe(
+ monkeypatch,
+ macos = False,
+ machine = "x86_64",
+ arm64_sysctl = "0",
+ git = "/usr/bin/git",
+ toolchain = False,
+ )
+ assert ran == [["/usr/bin/git", "--version"]]
+
+
+def test_no_git_on_path_runs_nothing(monkeypatch):
+ answer, ran = _probe(
+ monkeypatch,
+ macos = True,
+ machine = "arm64",
+ arm64_sysctl = "1",
+ git = None,
+ toolchain = False,
+ )
+ assert answer is False
+ assert ran == []
+
+
+def test_the_shim_path_matches_install_sh():
+ # Both probes have to agree on which git is the dialog shim, or one of them regresses alone.
+ install_sh = (REPO_ROOT / "install.sh").read_text(encoding = "utf-8")
+ assert '"${_CLT_GIT_SHIM:-/usr/bin/git}"' in install_sh
+ assert stack._CLT_GIT_SHIM == "/usr/bin/git"