diff --git a/src/env/node/gk/cli/commands.ts b/src/env/node/gk/cli/commands.ts index f7d60d69309a8..a2b17c964f5b8 100644 --- a/src/env/node/gk/cli/commands.ts +++ b/src/env/node/gk/cli/commands.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/require-await */ import type { Disposable } from 'vscode'; import type { CompareWithCommandArgs } from '../../../../commands/compareWith'; import type { Container } from '../../../../container'; @@ -67,7 +68,7 @@ export class CliCommandHandlers implements Disposable { _request: CliCommandRequest, repo?: Repository | undefined, ): Promise { - return cherryPick(repo); + void cherryPick(repo); } @command('compare') @@ -76,51 +77,48 @@ export class CliCommandHandlers implements Disposable { repo?: Repository | undefined, ): Promise { if (!repo || !_request.args?.length) { - await executeCommand('gitlens.compareWith'); + void executeCommand('gitlens.compareWith'); return; } const [ref1, ref2] = _request.args; if (!ref1 || !ref2) { - await executeCommand('gitlens.compareWith'); + void executeCommand('gitlens.compareWith'); return; } if (ref1) { if (!(await repo.git.refs().validateReference(ref1))) { - // TODO: Send an error back to the CLI? - await executeCommand('gitlens.compareWith'); - return; + void executeCommand('gitlens.compareWith'); + return { stderr: `${ref1} is an invalid reference` }; } } if (ref2) { if (!(await repo.git.refs().validateReference(ref2))) { - // TODO: Send an error back to the CLI? - await executeCommand('gitlens.compareWith', { ref1: ref1 }); - return; + void executeCommand('gitlens.compareWith', { ref1: ref1 }); + return { stderr: `${ref2} is an invalid reference` }; } } - await executeCommand('gitlens.compareWith', { ref1: ref1, ref2: ref2 }); + void executeCommand('gitlens.compareWith', { ref1: ref1, ref2: ref2 }); } @command('graph') async handleGraphCommand(request: CliCommandRequest, repo?: Repository | undefined): Promise { if (!repo || !request.args?.length) { - await executeCommand('gitlens.showGraphView'); + void executeCommand('gitlens.showGraphView'); return; } const [ref] = request.args; const reference = await repo.git.refs().getReference(ref); if (ref && !reference) { - // TODO: Send an error back to the CLI? - await executeCommand('gitlens.showInCommitGraph', repo); - return; + void executeCommand('gitlens.showInCommitGraph', repo); + return { stderr: `${ref} is an invalid reference` }; } - await executeCommand('gitlens.showInCommitGraph', { ref: reference }); + void executeCommand('gitlens.showInCommitGraph', { ref: reference }); } @command('merge') @@ -129,10 +127,12 @@ export class CliCommandHandlers implements Disposable { const [ref] = request.args; const reference = await repo.git.refs().getReference(ref); + + void merge(repo, reference); + if (ref && !reference) { - // TODO: Send an error back to the CLI? + return { stderr: `${ref} is an invalid reference` }; } - return merge(repo, reference); } @command('rebase') @@ -141,10 +141,11 @@ export class CliCommandHandlers implements Disposable { const [ref] = request.args; const reference = await repo.git.refs().getReference(ref); + + void rebase(repo, reference); + if (ref && !reference) { - // TODO: Send an error back to the CLI? + return { stderr: `${ref} is an invalid reference` }; } - - return rebase(repo, reference); } } diff --git a/src/env/node/gk/cli/integration.ts b/src/env/node/gk/cli/integration.ts index fd3105b956b16..cf8b02a24e674 100644 --- a/src/env/node/gk/cli/integration.ts +++ b/src/env/node/gk/cli/integration.ts @@ -3,14 +3,14 @@ import { Disposable } from 'vscode'; import type { Container } from '../../../../container'; import { configuration } from '../../../../system/-webview/configuration'; import { CliCommandHandlers } from './commands'; -import type { IpcServer } from './server'; -import { createIpcServer } from './server'; +import type { IpcServer } from './ipcServer'; +import { createIpcServer } from './ipcServer'; export interface CliCommandRequest { cwd?: string; args?: string[]; } -export type CliCommandResponse = string | void; +export type CliCommandResponse = { stdout?: string; stderr?: string } | void; export type CliIpcServer = IpcServer; export class GkCliIntegrationProvider implements Disposable { diff --git a/src/env/node/gk/cli/server.ts b/src/env/node/gk/cli/ipcServer.ts similarity index 93% rename from src/env/node/gk/cli/server.ts rename to src/env/node/gk/cli/ipcServer.ts index 9e665fba6c889..34505c47038fd 100644 --- a/src/env/node/gk/cli/server.ts +++ b/src/env/node/gk/cli/ipcServer.ts @@ -81,11 +81,18 @@ export class IpcServer implements Disposable const data = JSON.parse(Buffer.concat(chunks).toString('utf8')); try { const result = await handler(data); - res.writeHead(200); - if (result != null && typeof result === 'string') { + if (result == null) { + res.writeHead(200); + res.end(); + return; + } + + if (typeof result === 'string') { + res.writeHead(200); res.end(result); } else { - res.end(); + res.writeHead(200); + res.end(JSON.stringify(result)); } } catch (ex) { Logger.error(ex, 'IPC handler error', data);