I currenlty run emacs-nox on WSL2. My workflow is as such:

[Gentoo Linux Host] –ssh–> [WSL2 Ubuntu 22.04.2 LTS (Windows VM)] –open–> [emacs] –edit–> /mnt/c/<Path>/<Files>

There is a significant performance increase to using the windows git.exe instead of the one on Ubuntu in wsl as I am working primarily in /mnt/c/<Path>/<Files>

I setup magit-git-executable to use windows git.exe as follows:

(when (string-match "-[Mm]icrosoft" operating-system-release)
  (setq magit-git-executable "/mnt/c/Program Files/Git/cmd/git.exe"))

It works great; however, the only thing I cannot seem to get working is magit-commit

I did manage to get it working without emacs however.

I created a script in wsl to convert the git.exe path argument to a wsl path


WSL_PATH=$(wslpath -u "$1")
emacsclient "$WSL_PATH"

I then copied the command that magit-commit runs by grabbing it from M-x list-process in emacs and added -c "core.editor=wsl -e wslemacs".

git.exe --no-pager ... -c "core.editor=wsl -e wslemacs" commit --

When run from cmd.exe on windows it successfully opens COMMIT_EDITMSG in emacs running on wsl just as magit would.

I tried adding this to magit-git-global-arguments but still no luck.

I tried writing some output to a file from my wslemacs script to see if it was even being called when using magit-commit and it doesn't seem to be.

I tried using full paths to wsl and to my wslemacs script and still nothing works.

I was looking into magit-git.el and notice some stuff like magit-cygwin-mount-points that perhaps are hinting that something similar must be handled for wsl? I am really not sure.

What occurs when I try to commit in emacs with magit is it spawns a process to git.exe and it seems to just hang forever.

I tried looking at the with-editor-debug output but nothing jumps out at me. Happy to post if anyone thinks it would be helpful.

The only other thing I notice is that I think with-editor runs a separate emacs server than the one I was able to successfully commit when running git.exe directly from cmd.exe

Any help would be appreciated.

UPDATE I did a bit more digging. looks like this is the value of process-environment in the magit-start-process function in magit-process.el

"ALTERNATE_EDITOR=sh -c 'printf \"\\nWITH-EDITOR: $$ OPEN $0\\037 IN $(pwd)\\n\"; sleep 604800 & sleep=$!; trap \"kill $sleep; exit 0\" USR1; trap \"kill $sleep; exit 1\" USR2; wait $sleep'" "GIT_EDITOR=/usr/bin/emacsclient28 --socket-name=/tmp/emacs1000/server"
"SSH_CLIENT= 1685 2222"
"GIT_EDITOR=wsl -e wslemacs"
"LESSOPEN=| /usr/bin/lesspipe %s"
"LESSCLOSE=/usr/bin/lesspipe %s %s"
"SSH_CONNECTION= 1685 2222"
"EDITOR=wsl -e wslemacs"


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.