fix(git): support secure SSH config

This commit is contained in:
Bohdan Triapitsyn
2026-08-02 23:02:14 +03:00
parent 8ebf711f93
commit 134d055ee6
6 changed files with 42 additions and 15 deletions
+13 -8
View File
@@ -351,12 +351,17 @@ const buildGitEnv = async () => {
return env;
};
const createGit = async (directory) => {
const createGit = async (directory, { allowUnsafeSshCommand = false } = {}) => {
const env = await buildGitEnv();
const spawnOptions = { windowsHide: true };
const binary = getGitBinary();
const hasCustomBinary = typeof binary === 'string' && binary.trim() && binary !== 'git' && binary !== 'git.exe';
const unsafe = hasCustomBinary ? { allowUnsafeCustomBinary: true } : undefined;
const unsafe = hasCustomBinary || allowUnsafeSshCommand
? {
...(hasCustomBinary && { allowUnsafeCustomBinary: true }),
...(allowUnsafeSshCommand && { allowUnsafeSshCommand: true }),
}
: undefined;
// Always pin simple-git to an explicit working directory. Omitting baseDir
// makes simple-git use process.cwd(), which breaks when the OpenChamber
// server was launched from a neutral directory (e.g. $HOME) and the opened
@@ -2047,7 +2052,7 @@ export async function hasLocalIdentity(directory) {
}
export async function setLocalIdentity(directory, profile) {
const git = await createGit(directory);
const git = await createGit(directory, { allowUnsafeSshCommand: true });
try {
@@ -2057,12 +2062,12 @@ export async function setLocalIdentity(directory, profile) {
const authType = profile.authType || 'ssh';
if (authType === 'ssh' && profile.sshKey) {
await git.addConfig(
await git.raw([
'config',
'--local',
'core.sshCommand',
buildSshCommand(profile.sshKey),
false,
'local'
);
buildSshCommand(profile.sshKey)
]);
await git.raw(['config', '--local', '--unset', 'credential.helper']).catch(() => {});
} else if (authType === 'token' && profile.host) {
await git.addConfig(