Skip to content
Merged
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
4 changes: 2 additions & 2 deletions extensions/git/src/askpass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/

import { window, InputBoxOptions, Uri, Disposable, workspace, QuickPickOptions, l10n, LogOutputChannel } from 'vscode';
import { IDisposable, EmptyDisposable, toDisposable } from './util';
import { IDisposable, EmptyDisposable, toDisposable, extractFilePathFromArgs } from './util';
import * as path from 'path';
import { IIPCHandler, IIPCServer } from './ipc/ipcServer';
import { CredentialsProvider, Credentials } from './api/git';
Expand Down Expand Up @@ -108,7 +108,7 @@ export class Askpass implements IIPCHandler, ITerminalEnvironmentProvider {
if (/passphrase/i.test(request)) {
// Commit signing - Enter passphrase:
// Git operation - Enter passphrase for key '/c/Users/<username>/.ssh/id_ed25519':
const file = argv[6]?.replace(/^["']+|["':]+$/g, '');
const file = extractFilePathFromArgs(argv, 6);

this.logger.trace(`[Askpass][handleSSHAskpass] request: ${request}, file: ${file}`);

Expand Down
32 changes: 32 additions & 0 deletions extensions/git/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,35 @@ export function toDiagnosticSeverity(value: DiagnosticSeverityConfig): Diagnosti
? DiagnosticSeverity.Information
: DiagnosticSeverity.Hint;
}

export function extractFilePathFromArgs(argv: string[], startIndex: number): string {
// Argument doesn't start with a quote
const firstArg = argv[startIndex];
if (!firstArg.match(/^["']/)) {
return firstArg.replace(/^["']+|["':]+$/g, '');
}

// If it starts with a quote, we need to find the matching closing
// quote which might be in a later argument if the path contains
// spaces
const quote = firstArg[0];

// If the first argument ends with the same quote, it's complete
if (firstArg.endsWith(quote) && firstArg.length > 1) {
return firstArg.slice(1, -1);
}

// Concatenate arguments until we find the closing quote
let path = firstArg;
for (let i = startIndex + 1; i < argv.length; i++) {
path = `${path} ${argv[i]}`;
if (argv[i].endsWith(quote)) {
// Found the matching quote
return path.slice(1, -1);
}
}

// If no closing quote was found, remove
// leading quote and return the path as-is
return path.slice(1);
}
Loading