From 1ac3ba0015c735a2c6727af4e34787eb1668fca0 Mon Sep 17 00:00:00 2001 From: Krzysztof Zbudniewek Date: Mon, 30 Oct 2017 00:35:17 +0100 Subject: [PATCH] fix(git): Fix installing package over git+ssh with non-standard port using plink on Windows Fixes #4729. --- __tests__/util/git/git-spawn.js | 3 ++- bin/yarn-plink.cmd | 33 +++++++++++++++++++++++++++++++++ src/util/git/git-spawn.js | 9 ++++++--- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 bin/yarn-plink.cmd diff --git a/__tests__/util/git/git-spawn.js b/__tests__/util/git/git-spawn.js index 22b2b8e6de..da51a82ebe 100644 --- a/__tests__/util/git/git-spawn.js +++ b/__tests__/util/git/git-spawn.js @@ -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']); @@ -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, }); }); diff --git a/bin/yarn-plink.cmd b/bin/yarn-plink.cmd new file mode 100644 index 0000000000..cb438e4b5c --- /dev/null +++ b/bin/yarn-plink.cmd @@ -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% diff --git a/src/util/git/git-spawn.js b/src/util/git/git-spawn.js index b445bbd7d5..ae3c1088b7 100644 --- a/src/util/git/git-spawn.js +++ b/src/util/git/git-spawn.js @@ -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 = { @@ -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, opts?: child_process$spawnOpts = {}): Promise => {