Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src-node/git/processUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ var exec = require("child_process").exec,
which = require("which");

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

// Cache for xcode-select CLT check (null = not yet checked)
var _xcodeCliToolsInstalled = null;

function _isXcodeCliToolsInstalled(callback) {
if (_xcodeCliToolsInstalled !== null) {
return callback(_xcodeCliToolsInstalled);
}
exec("xcode-select -p", function (err) {
_xcodeCliToolsInstalled = !err;
callback(_xcodeCliToolsInstalled);
});
}

function fixEOL(str) {
if (str[str.length - 1] === "\n") {
str = str.slice(0, -1);
Expand Down Expand Up @@ -104,6 +118,17 @@ function executableExists(filename, dir, callback) {
var exists = stats.isFile();
if (!exists) { path = undefined; }

// On macOS, /usr/bin/git is a shim that triggers an "Install Xcode CLT" dialog
// when spawned if CLT is not installed. Check for CLT before allowing it.
if (exists && isMac && Path.normalize(path) === "/usr/bin/git") {
return _isXcodeCliToolsInstalled(function (installed) {
if (!installed) {
return callback(null, false, undefined);
}
return callback(null, true, path);
});
}

return callback(null, exists, path);
});
});
Expand Down
4 changes: 2 additions & 2 deletions src-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 28 additions & 3 deletions src/extensions/default/Git/src/git/GitCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,9 +1022,33 @@ define(function (require, exports) {

function getGitRoot() {
var projectRoot = Utils.getProjectRoot();
return git(["rev-parse", "--show-toplevel"], {
cwd: fs.getTauriPlatformPath(projectRoot)
})

// Quick filesystem pre-check: if .git doesn't exist in the project root,
// skip spawning git entirely. This avoids triggering macOS CLT shim dialogs
// on non-git projects and is a minor optimization on all platforms.
return new Promise(function (resolve) {
var checkPath = projectRoot;
if (strEndsWith(checkPath, "/")) {
checkPath = checkPath.slice(0, -1);
}
if (typeof brackets !== "undefined" && brackets.fs && brackets.fs.stat) {
brackets.fs.stat(checkPath + "/.git", function (err, result) {
var exists = err ? false : (result.isFile() || result.isDirectory());
resolve(exists);
});
} else {
FileSystem.resolve(checkPath + "/.git", function (err, item, stat) {
var exists = err ? false : (stat.isFile || stat.isDirectory);
resolve(exists);
});
}
}).then(function (hasGitDir) {
if (!hasGitDir) {
return null;
}
return git(["rev-parse", "--show-toplevel"], {
cwd: fs.getTauriPlatformPath(projectRoot)
})
.catch(function (e) {
if (ErrorHandler.contains(e, "Not a git repository")) {
return null;
Expand Down Expand Up @@ -1095,6 +1119,7 @@ define(function (require, exports) {
});

});
});
}

function setTagName(tagname, commitHash) {
Expand Down
5 changes: 3 additions & 2 deletions src/extensions/default/Git/src/utils/Setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ define(function (require, exports) {
];

let standardGitPathsNonWin = [
"/opt/homebrew/bin/git", // Apple Silicon Homebrew
"/usr/local/git/bin/git",
"/usr/local/bin/git",
"/usr/bin/git"
"/usr/bin/git" // macOS CLT shim check handled on node side
];

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

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

Expand Down
Loading