Skip to content

Commit

Permalink
Merge pull request #302 from the-kenny/fix-301-commit-editmsg-window
Browse files Browse the repository at this point in the history
  • Loading branch information
kahole authored Nov 19, 2024
2 parents f25a828 + 06eaf1d commit 3fa9a37
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/commands/commitCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit 3fa9a37

Please sign in to comment.