From 06eaf1d48d927b79e0d0b69af3bb79e76f462028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20von=20G=C3=B6wels?= Date: Tue, 11 Jun 2024 12:10:11 +0200 Subject: [PATCH] `runCommitLikeCommand`: Open COMMIT_EDITMSG in the current workspace Fixes #301 --- src/commands/commitCommands.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/commands/commitCommands.ts b/src/commands/commitCommands.ts index 688a289..a1e33ce 100644 --- a/src/commands/commitCommands.ts +++ b/src/commands/commitCommands.ts @@ -122,10 +122,24 @@ export async function runCommitLikeCommand(repository: MagitRepository, args: st stagedEditorTask = Diffing.showDiffSection(repository, Section.Staged, true); } - const env: NodeJS.ProcessEnv = { 'GIT_EDITOR': `"${codePath}" --wait` }; + // This passes the path to (the first) open workspace as the first command + // to the `code` command when invoked as `GIT_EDITOR`. This together with + // `--reuse-window` forces VSCode to open COMMIT_EDITMSG in the current + // workspace even if the file is more closely related to a different + // window/workspace. + // + // https://github.com/kahole/edamagit/issues/301 + let currentInstancePath = ''; + if (vscode.workspace.workspaceFolders?.at(0)) { + currentInstancePath = vscode.workspace.workspaceFolders[0].uri.fsPath; + } + + const cmd = `"${codePath}" --wait --reuse-window ${currentInstancePath} `; + + const env: NodeJS.ProcessEnv = { 'GIT_EDITOR': cmd }; if (editor) { - env[editor] = `"${codePath}" --wait`; + env[editor] = cmd; } const commitSuccessMessageTask = gitRun(repository.gitRepository, args, { env });