Skip to content

Commit 1e78804

Browse files
committed
fix: in macs without git, xcode git install dialog comes up when phoenix code starts always
1 parent 8a4b68e commit 1e78804

4 files changed

Lines changed: 58 additions & 7 deletions

File tree

src-node/git/processUtils.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,22 @@ var exec = require("child_process").exec,
44
which = require("which");
55

66
var isWin = /^win/.test(process.platform);
7+
var isMac = process.platform === "darwin";
78
var noop = function () {};
89

10+
// Cache for xcode-select CLT check (null = not yet checked)
11+
var _xcodeCliToolsInstalled = null;
12+
13+
function _isXcodeCliToolsInstalled(callback) {
14+
if (_xcodeCliToolsInstalled !== null) {
15+
return callback(_xcodeCliToolsInstalled);
16+
}
17+
exec("xcode-select -p", function (err) {
18+
_xcodeCliToolsInstalled = !err;
19+
callback(_xcodeCliToolsInstalled);
20+
});
21+
}
22+
923
function fixEOL(str) {
1024
if (str[str.length - 1] === "\n") {
1125
str = str.slice(0, -1);
@@ -104,6 +118,17 @@ function executableExists(filename, dir, callback) {
104118
var exists = stats.isFile();
105119
if (!exists) { path = undefined; }
106120

121+
// On macOS, /usr/bin/git is a shim that triggers an "Install Xcode CLT" dialog
122+
// when spawned if CLT is not installed. Check for CLT before allowing it.
123+
if (exists && isMac && Path.normalize(path) === "/usr/bin/git") {
124+
return _isXcodeCliToolsInstalled(function (installed) {
125+
if (!installed) {
126+
return callback(null, false, undefined);
127+
}
128+
return callback(null, true, path);
129+
});
130+
}
131+
107132
return callback(null, exists, path);
108133
});
109134
});

src-node/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/extensions/default/Git/src/git/GitCli.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,9 +1022,33 @@ define(function (require, exports) {
10221022

10231023
function getGitRoot() {
10241024
var projectRoot = Utils.getProjectRoot();
1025-
return git(["rev-parse", "--show-toplevel"], {
1026-
cwd: fs.getTauriPlatformPath(projectRoot)
1027-
})
1025+
1026+
// Quick filesystem pre-check: if .git doesn't exist in the project root,
1027+
// skip spawning git entirely. This avoids triggering macOS CLT shim dialogs
1028+
// on non-git projects and is a minor optimization on all platforms.
1029+
return new Promise(function (resolve) {
1030+
var checkPath = projectRoot;
1031+
if (strEndsWith(checkPath, "/")) {
1032+
checkPath = checkPath.slice(0, -1);
1033+
}
1034+
if (typeof brackets !== "undefined" && brackets.fs && brackets.fs.stat) {
1035+
brackets.fs.stat(checkPath + "/.git", function (err, result) {
1036+
var exists = err ? false : (result.isFile() || result.isDirectory());
1037+
resolve(exists);
1038+
});
1039+
} else {
1040+
FileSystem.resolve(checkPath + "/.git", function (err, item, stat) {
1041+
var exists = err ? false : (stat.isFile || stat.isDirectory);
1042+
resolve(exists);
1043+
});
1044+
}
1045+
}).then(function (hasGitDir) {
1046+
if (!hasGitDir) {
1047+
return null;
1048+
}
1049+
return git(["rev-parse", "--show-toplevel"], {
1050+
cwd: fs.getTauriPlatformPath(projectRoot)
1051+
})
10281052
.catch(function (e) {
10291053
if (ErrorHandler.contains(e, "Not a git repository")) {
10301054
return null;
@@ -1095,6 +1119,7 @@ define(function (require, exports) {
10951119
});
10961120

10971121
});
1122+
});
10981123
}
10991124

11001125
function setTagName(tagname, commitHash) {

src/extensions/default/Git/src/utils/Setup.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ define(function (require, exports) {
1616
];
1717

1818
let standardGitPathsNonWin = [
19+
"/opt/homebrew/bin/git", // Apple Silicon Homebrew
1920
"/usr/local/git/bin/git",
2021
"/usr/local/bin/git",
21-
"/usr/bin/git"
22+
"/usr/bin/git" // macOS CLT shim check handled on node side
2223
];
2324

2425
let extensionActivated = false;
@@ -27,7 +28,7 @@ define(function (require, exports) {
2728
function getGitVersion() {
2829
return new Promise(function (resolve, reject) {
2930

30-
// TODO: do this in two steps - first check user config and then check all
31+
// User-configured path gets priority, then "git" (PATH lookup), then standard paths
3132
var pathsToLook = [Preferences.get("gitPath"), "git"].concat(brackets.platform === "win" ? standardGitPathsWin : standardGitPathsNonWin);
3233
pathsToLook = _.unique(_.compact(pathsToLook));
3334

0 commit comments

Comments
 (0)