fix(git): support secure SSH config
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user