mirror of
https://github.com/zhigang1992/yarn.git
synced 2026-06-12 09:18:58 +08:00
**Summary** Fixes #4729. Previous version in #4805. Manually specify `GIT_SSH_VARIANT` in order to get package download via `git+ssh` with a non-standard port when using `plink.exe` working. Without `GIT_SSH_VARIANT` set properly, Git won't convert `-p` into `-P` and `plink.exe` will throw an error about unknown `-p` parameter. **Test plan** *Before:*  *After:*  Also got `git-spawn.js` test suite updated for testing `GIT_SSH_VARIANT`.
94 lines
2.3 KiB
JavaScript
94 lines
2.3 KiB
JavaScript
/* @flow */
|
|
|
|
import path from 'path';
|
|
|
|
jest.mock('../../../src/util/child.js', () => {
|
|
const realChild = (require: any).requireActual('../../../src/util/child.js');
|
|
|
|
realChild.spawn = jest.fn(() => Promise.resolve(''));
|
|
|
|
return realChild;
|
|
});
|
|
|
|
function runGit(args, opts): any {
|
|
const {spawn} = require('../../../src/util/child.js');
|
|
const {spawn: spawnGit} = require('../../../src/util/git/git-spawn.js');
|
|
const spawnMock = (spawn: any).mock;
|
|
|
|
spawnGit(args, opts);
|
|
|
|
return spawnMock.calls[0];
|
|
}
|
|
|
|
describe('spawn', () => {
|
|
beforeEach(() => {
|
|
jest.resetModules();
|
|
});
|
|
|
|
test('spawn with default', () => {
|
|
process.env.GIT_SSH_COMMAND = '';
|
|
const gitCall = runGit(['status']);
|
|
delete process.env.GIT_SSH_COMMAND;
|
|
|
|
expect(gitCall[2].env).toMatchObject({
|
|
GIT_ASKPASS: '',
|
|
GIT_TERMINAL_PROMPT: 0,
|
|
GIT_SSH_COMMAND: '"ssh" -oBatchMode=yes',
|
|
GIT_SSH_VARIANT: 'ssh',
|
|
...process.env,
|
|
});
|
|
});
|
|
|
|
test('spawn with plink', () => {
|
|
process.env.GIT_SSH_COMMAND = '';
|
|
// Test for case-sensitivity too (should be insensitive)
|
|
const plinkPath = path.join('C:', 'pLink.EXE');
|
|
process.env.GIT_SSH = plinkPath;
|
|
|
|
const gitCall = runGit(['status']);
|
|
delete process.env.GIT_SSH_COMMAND;
|
|
|
|
delete process.env.GIT_SSH;
|
|
|
|
expect(gitCall[2].env).toMatchObject({
|
|
GIT_ASKPASS: '',
|
|
GIT_TERMINAL_PROMPT: 0,
|
|
GIT_SSH_COMMAND: `"${plinkPath}" -batch`,
|
|
GIT_SSH_VARIANT: 'plink',
|
|
...process.env,
|
|
});
|
|
});
|
|
|
|
test('spawn with custom GIT_SSH', () => {
|
|
process.env.GIT_SSH_COMMAND = '';
|
|
process.env.GIT_SSH = 'custom-ssh.sh';
|
|
const gitCall = runGit(['status']);
|
|
|
|
delete process.env.GIT_SSH;
|
|
delete process.env.GIT_SSH_COMMAND;
|
|
|
|
const calledEnv = gitCall[2].env;
|
|
expect(calledEnv).toMatchObject({
|
|
GIT_ASKPASS: '',
|
|
GIT_TERMINAL_PROMPT: 0,
|
|
GIT_SSH_COMMAND: '',
|
|
...process.env,
|
|
});
|
|
});
|
|
|
|
test('spawn with custom GIT_SSH_COMMAND', () => {
|
|
process.env.GIT_SSH_COMMAND = 'some-custom-ssh.sh';
|
|
const gitCall = runGit(['status']);
|
|
|
|
delete process.env.GIT_SSH_COMMAND;
|
|
|
|
const calledEnv = gitCall[2].env;
|
|
expect(calledEnv).toMatchObject({
|
|
GIT_ASKPASS: '',
|
|
GIT_TERMINAL_PROMPT: 0,
|
|
GIT_SSH_COMMAND: 'some-custom-ssh.sh',
|
|
...process.env,
|
|
});
|
|
});
|
|
});
|