Skip to content
Closed
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
3 changes: 2 additions & 1 deletion __tests__/util/git/git-spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('spawn', () => {
process.env.GIT_SSH_COMMAND = '';
// Test for case-sensitivity too (should be insensitive)
const plinkPath = path.join('C:', 'pLink.EXE');
const plinkWrapperPath = path.join(__dirname, '..', '..', '..', 'bin', 'yarn-plink.cmd');
process.env.GIT_SSH = plinkPath;

const gitCall = runGit(['status']);
Expand All @@ -52,7 +53,7 @@ describe('spawn', () => {
expect(gitCall[2].env).toMatchObject({
GIT_ASKPASS: '',
GIT_TERMINAL_PROMPT: 0,
GIT_SSH_COMMAND: `"${plinkPath}" -batch`,
GIT_SSH_COMMAND: `"${plinkWrapperPath}" "${plinkPath}" -batch`,
...process.env,
});
});
Expand Down
33 changes: 33 additions & 0 deletions bin/yarn-plink.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@echo off

set PLINK_PATH="%~1"
set PARAMS=""

REM Shift params once at the beginning to exclude the first one
shift

REM Start of the loop
:params_loop
if "%~1"=="" (
REM If we went through all the params, go to the end of the loop
goto after_params_loop
)

if "%~1"=="-p" (
REM If the param is `-p`, append it to `PARAMS` as a `-P` required by `plink.exe`
set PARAMS=%PARAMS% "-P"
) else (
REM Else, just append the parameter to `PARAMS`
set PARAMS=%PARAMS% %1
)

REM Shift the params again
shift

REM Start the loop again
goto params_loop
REM End of the loop
:after_params_loop

REM Run given plink.exe with proper params
%PLINK_PATH% %PARAMS%
9 changes: 6 additions & 3 deletions src/util/git/git-spawn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import * as child from '../child.js';

const BATCH_MODE_ARGS = new Map([['ssh', '-oBatchMode=yes'], ['plink', '-batch']]);
const WRAPPER_PATHS = new Map([['plink', path.resolve(__dirname, '..', '..', '..', 'bin', 'yarn-plink.cmd')]]);

// Suppress any password prompts since we run these in the background
const env = {
Expand All @@ -14,11 +15,13 @@ const env = {
};

const sshCommand = env.GIT_SSH || 'ssh';
const sshExecutable = path.basename(sshCommand.toLowerCase(), '.exe');
const sshBatchArgs = BATCH_MODE_ARGS.get(sshExecutable);
const sshBasename = path.basename(sshCommand.toLowerCase(), '.exe');
const sshWrapper = WRAPPER_PATHS.get(sshBasename);
const sshExecutable = sshWrapper ? `"${sshWrapper}" "${sshCommand}"` : `"${sshCommand}"`;
const sshBatchArgs = BATCH_MODE_ARGS.get(sshBasename);

if (!env.GIT_SSH_COMMAND && sshBatchArgs) {
env.GIT_SSH_COMMAND = `"${sshCommand}" ${sshBatchArgs}`;
env.GIT_SSH_COMMAND = `${sshExecutable} ${sshBatchArgs}`;
}

export const spawn = (args: Array<string>, opts?: child_process$spawnOpts = {}): Promise<string> => {
Expand Down