Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/git/src/askpass-main.ts
3314 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import * as fs from 'fs';
7
import { IPCClient } from './ipc/ipcClient';
8
9
function fatal(err: any): void {
10
console.error('Missing or invalid credentials.');
11
console.error(err);
12
process.exit(1);
13
}
14
15
function main(argv: string[]): void {
16
if (!process.env['VSCODE_GIT_ASKPASS_PIPE']) {
17
return fatal('Missing pipe');
18
}
19
20
if (!process.env['VSCODE_GIT_ASKPASS_TYPE']) {
21
return fatal('Missing type');
22
}
23
24
if (process.env['VSCODE_GIT_ASKPASS_TYPE'] !== 'https' && process.env['VSCODE_GIT_ASKPASS_TYPE'] !== 'ssh') {
25
return fatal(`Invalid type: ${process.env['VSCODE_GIT_ASKPASS_TYPE']}`);
26
}
27
28
if (process.env['VSCODE_GIT_COMMAND'] === 'fetch' && !!process.env['VSCODE_GIT_FETCH_SILENT']) {
29
return fatal('Skip silent fetch commands');
30
}
31
32
const output = process.env['VSCODE_GIT_ASKPASS_PIPE'];
33
const askpassType = process.env['VSCODE_GIT_ASKPASS_TYPE'] as 'https' | 'ssh';
34
35
const ipcClient = new IPCClient('askpass');
36
ipcClient.call({ askpassType, argv })
37
.then(res => {
38
fs.writeFileSync(output, res + '\n');
39
setTimeout(() => process.exit(0), 0);
40
}).catch(err => fatal(err));
41
}
42
43
main(process.argv);
44
45