obsidian-git: [Bug]: custom Git binary path using wsl doesn't work
[note: suspected cause at the very end; skip ahead and come back if that’s not it]
I have Git installed in WSL and added a shell script in my home that will take care of connecting to the ssh-agent etc. followed by actually running the requested git command. Despite the command working in both PowerShell and plain CMD, Obsidian Git reports “cannot run git command”.
- Are you sure that the custom git binary path code actually works?
- If yes, what’s the required format?
I have tried both C:\Windows\System32\wsl.exe /home/REDACTED/bin/ogit as well as just wsl.exe /home/REDACTED/bin/ogit or wsl /home/REDACTED/bin/ogit (in case there’s a problem with handling backslashes…)
In CMD and PowerShell, both work:
C:\Users\REDACTED\Desktop\maps\obsidian>wsl /home/REDACTED/bin/ogit status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .obsidian/plugins/obsidian-git/data.json
C:\Users\REDACTED\Desktop\maps\obsidian>C:\Windows\System32\wsl.exe /home/REDACTED/bin/ogit status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: .obsidian/plugins/obsidian-git/data.json
C:\Users\REDACTED\Desktop\maps\obsidian>C:\Windows\System32\wsl.exe /home/REDACTED/bin/ogit push
Host key fingerprint is SHA256:<redacted>
Enumerating objects: 38, done.
Counting objects: 100% (38/38), done.
Delta compression using up to 8 threads
Compressing objects: 100% (27/27), done.
Writing objects: 100% (29/29), 6.13 KiB | 184.00 KiB/s, done.
Total 29 (delta 4), reused 0 (delta 0)
To <redacted>:repos/obsidian-vault.git
<redacted>..<redacted> master -> master
In Obsidian, all variants fail.
So there seems to be some special formatting / adjustment to the command required to make it work when run from Obsidian. (Or maybe it just doesn’t work at all?)
While I don’t really understand JS & related languages, from a quick scan of the code in src/simpleGit.ts, the following seem strange:
isGitInstalled,commitAll, andpushall appear to hard-code thegitcommand; ifisGitInstalledgatekeeps the running of all other commands, then it’s not surprising that nothing works
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 15
Progress! After the update, I’m getting
/bin/bash: status: command not foundwhich is exactly the error message thatwsl statusgenerates.So it looks like something drops the second part of
wsl /home/REDACTED/bin/ogit, and I confirmed that with an experiment. (Details below.)For now, I added an extra
git.cmdwrapper somewhere in the%PATH%and then wondered why it doesn’t work until I found out that apparently I need to add the fullC:\...path in spite of it being in%PATH%(where both cmd and powershell find & run it without problems). So now things mostly work for me!I’d love to see the argument-dropping problem fixed eventually (so I no longer need the second wrapper) but it’s not urgent.
Experiment: To test the argument dropping, I added symlinks named
status,branch, … in/usr/local/binto another wrapper that calls/home/REDACTED/bin/ogit "$(basename "$0")" "$@"(i.e. reroutes those program names to become a git command), such thatwsl status,wsl branch, … will work likewsl /home/REDACTED/bin/ogit status, … and that confirms this guess: With that in place, I can select the branch from the drop-down in the obsidian-git config and I get a “git: ready” in the status bar, i.e. basic communication with git works. (Adding lots of other wrappers foradd/commit/push/… means I can use the source control view to add, commit, push/pull and it all works, as verified externally.)Just for reference, in case others want my full solution for getting WSL’s git working: There’s a
git.cmdand since
%PATH%search doesn’t work anyway, just place that anywhere and specify the full path to it as the custom command. On the Linux side, there’s theobsidian-gitwrapper that connects to the runningssh-agentand then calls git:and in case you don’t have an automated
ssh-agentsetup yet,eval "$(keychain --eval --agents ssh)"in e.g. your.profilewithkeychaininstalled gets that done without lots of duplicatessh-agents. (Justssh-addthe key once after boot to unlock/cache it and you’re done.)Just noticed activity on this issue - wanted to put in my 2 cents since I have a working solution that satisfies me.
My motivation: I want Windows Obsidian to use WSL’s git for
obsidian-git, because my WSL has my ssh keys in the agent and also my git repo hasgit-cryptset up.obsidian-gitpatched with #587 (just updated to latest in my fork)C:\Users\<user>\AppData\Local\scripts\wsl_git.cmdI believe I didnt run into the issue described above simply because my Windows user has no spaces. I’d suggest attempting to escape them with\, but can’t test that theory.wsl_git.cmd, inspired by this thread:~/bin/obsidian-git, which ensures my env is properly set up (most importantly, the correctSSH_AUTH_SOCK):The last one is optional, if you don’t need your
.profileyou can just havewsl_git.cmdpointing to the wsl git binary instead.With this setup,
obsidian-gitpulls and pushes to my remote seamlessly using my WSL auth configuration.Hope this helps!