obsidian-git icon indicating copy to clipboard operation
obsidian-git copied to clipboard

[Bug]: pull/push not working with keybase encrypted git

Open jajcayn opened this issue 3 years ago • 15 comments

Describe the bug

I set up my vault as a keybase git repo with:

cd <obsidian vault>
git init
git remote add origin keybase://private/XXXX/YYYY
git add -v .
git commit -m "first commit"
git push -u origin main

this worked nicely. Note, that with keybase repo, I can use git commands like with any other provider, i.e. simply git pull origin main, git push origin main, git branch, git rebase, etc., nothing special. Then I installed obsidian git plugin, it can correctly see changes, it can stage changes and commit then (I was able to confirm in the terminal that when clicking on the commit button, git sees that as a proper commit). However, when I try to push or pull, I am getting

git: 'remote-keybase' is not a git command. See 'git --help'.
Screenshot 2022-02-25 at 15 08 08

Now, I feel I know why, but tbh, I don't understand why :) The thing is when git plugin would simply run git push / git pull, this shouldn't happen. Is there a way to fix this? Thanks! N.

P.S., if it matters, I am on macOS 12.2.1, keybase 5.9.2-20220131221715+a25f15e42b, and obsidian 0.13.23

Relevant errors (if available)

No response

Steps to reproduce

  1. have keybase and obsidian handy
  2. set up Obsidian vault
  3. create keybase encrypted repo in the keybase app or in terminal
  4. cd to repo
  5. git init, git add remote, git add, git commit, git push
  6. install obsidian-git
  7. try to pull / push
  8. error

Expected Behavior

I hoped this would work without any problems, since once the keybase repo is initialized, it works like any other git repo with credentials setup

Addition context

No response

Operating system

macOS

jajcayn avatar Feb 25 '22 14:02 jajcayn

By researching the error message, it may be a path problem. Can you try some solutions provided in this issue? https://github.com/keybase/client/issues/15176 Interesting comments:

  • https://github.com/keybase/client/issues/15176#issuecomment-501716617
  • https://github.com/keybase/client/issues/15176#issuecomment-845304953

Vinzent03 avatar Feb 25 '22 17:02 Vinzent03

Hey @Vinzent03, Thanks for getting back to me. Unfortunately no, all those issues describe a problem with PATH, where OPs cannot use git push / git pull with keybase repo because the helper is not in their PATH. However, I do have git-remote-keybase in my PATH, and I am able to use git push / git pull without problems:

Screenshot 2022-02-25 at 20 54 13

So, the problem must lie elsewhere :/

jajcayn avatar Feb 25 '22 19:02 jajcayn

Hmm, then I don't know what the issue could be. Sorry.

Vinzent03 avatar Feb 25 '22 20:02 Vinzent03

I have exactly the same error on Linux using Keybase 5.9.1-1 and Obsidian v0.13.23. git-remote-keybase is in my PATH and so is git itself. I can push/pull without a problem inside the terminal. However, the obsidian-git plugin is only able to commit, but when it comes to pushing the changes, I get the error as described. So for now, I have to pull and push manually in the terminal.

maximilianproell avatar Mar 05 '22 23:03 maximilianproell

@maximilianproell I'm experiencing a similar problem, but it isn't with Keybase. Mine is pushing to a remote URL that's setup as "https+iap://gitlab-url.com/".

In any case, the issue comes up because the simpleGit library that obsidian-git works by parsing the output that comes from Git. I believe our use cases are unique and aren't factored into the output parsing.

Can you do a git fetch origin <your-branch> and a git push origin <your-branch> in your repo and paste me both of their output?

catherinetcai avatar Mar 09 '22 06:03 catherinetcai

@catherinetcai for git fetch origin <your-branch> I get:

Initializing Keybase... done.
Syncing with Keybase... done.
Von keybase://private/username/obsidian-vault
 * branch            master     -> FETCH_HEAD

and for git push origin <your-branch> I get:

Initializing Keybase... done.
Syncing with Keybase... done.
Preparing and encrypting: (100.00%) 15/15 objects... done.
Indexing hashes: (86.67%) 13/15 objects... done.
Indexing CRCs: (93.33%) 14/15 objects... done.
Indexing offsets: (93.33%) 14/15 objects... done.
Syncing encrypted data to Keybase: (100.00%) 23.20/23.20 KB... done.
Syncing encrypted data to Keybase: (100.00%) 2.92/2.92 KB... done.
To keybase://private/username/obsidian-vault
   8acf8c1..00daebd  master -> master

maximilianproell avatar Mar 09 '22 10:03 maximilianproell

Awesome, thanks for that @maximilianproell. I dug into the issue more today. The parsing issue was a red-herring, so never mind on that... it was actually something else...

Some background What's happening underneath when you call git push on your repo is that git is invoking a gitremote-helper to handle a different transport protocol. In your case, the protocol is "keybase", because your git remote url is something like: keybase://private//. The remote helper is actually this thing. When you use Keybase for git, it added a remote helper, probably in /usr/local/bin. If you call ls there, you'll probably see git-remote-keybase (which is symlinked to something else, but that's irrelevant.) In any case, you can directly call git-remote-keybase.

Anyway... so why doesn't this work with Obsidian Git? I did an ungodly amount of console.log in simple-git to try and hunt things down. simple-git calls git commands by spawning child processes, then doing some parsing on the response from git. I spawned a child process in the same way and then called env in the child process and got the output.

My $PATH includes /usr/local/bin, which is why I'm able to execute git-remote-keybase. However, in the child process env, the $PATH variable is different (PATH=/usr/bin:/bin:/usr/sbin:/sbin to be precise), meaning that when git-remote-keybase is invoked, the child process won't be able to call it properly.

What's the fix? I'm not 100% sure, but I believe it'll be either 1) copying or symlinking the git-remote-keybase binary to one of those directories in $PATH, (which you probably won't be allowed to do if you're on a Mac due to SIP) OR 2) finding a way to add /usr/local/bin into the child process env. This plugin is already passing in env vars down to the process, as evidenced here.

catherinetcai avatar Mar 10 '22 06:03 catherinetcai

Thanks for the input @catherinetcai!. Actually, in my case, /usr/local/bin/ is empty. git-remote-keybase is in my /usr/bin/ folder. Checking my system where the problem could be, I finally realized what the issue is: I installed Obsidian via flatpak. The thing with flatpak Apps is that they are installed in their own sandbox environment. I therefore added the /usr/bin/ path to the filesystem subset of the Obsidian flatpak sandbox. However, that did not work for some reason. I then uninstalled the flatpak version and installed it normally using pacman. That solved the issue!

maximilianproell avatar Mar 10 '22 09:03 maximilianproell

hey @catherinetcai ! Nice find! Option 1 is not viable for me, since I am on Mac... I'd be glad to do option 2, but I have no idea how to proceed. Also, I am wondering - in the settings of Obsidian git you can specify custom git binary (I have there /usr/local/bin/git), so I am thinking - if I do that that the child process should also include /usr/local/bin in $PATH, no? If that wasn't the case, and the child process would still only contain basic paths, then the git binary used wouldn't be the same as the user-specified one... And of course, I do have git-remote-keybase in /usr/local/bin so, for me, that is an extra level of confusion...

jajcayn avatar Mar 10 '22 10:03 jajcayn

@jajcayn Not 100% sure about your setup, but... when you specify your custom git binary, I believe you have to provide the absolute path to it, right? I believe the child processes are able to use the custom git binary because they're always referring to the absolute path /usr/local/bin/git. This will still work just fine even if /usr/local/bin isn't in your $PATH.

Let me get a fork going with a test and see if that will solve both our problems, and if it does, then I'll try and propose an actual fix.

catherinetcai avatar Mar 10 '22 15:03 catherinetcai

Hi there, I am watching this issue, was there any updates, or did anyone find a workaround for the moment? Thanks!

jptechnical avatar Apr 20 '22 05:04 jptechnical

The issue with the path seems to be very similar to the problems encountered with using Git LFS. See #14. They have similar issues and similar solutions.

It seems that /usr/local/bin is not included by default - which breaks keybase integration, Git LFS and possibly other tools as well.

Could it be, that this behavior is set so as the default by the Obsidian Developers? Could it make sense, to have them include usr/bin/local as env for plugins by default instead of adding this in this obsidian git plugin?

GollyTicker avatar May 16 '22 18:05 GollyTicker

@GollyTicker I can execute files in /usr/local/bin on my Ubuntu 20.04 machine from within Obsidian. But maybe that's not always the case?

Vinzent03 avatar May 18 '22 08:05 Vinzent03

The issue with the path seems to be very similar to the problems encountered with using Git LFS. See #14. They have similar issues and similar solutions.

It seems that /usr/local/bin is not included by default - which breaks keybase integration, Git LFS and possibly other tools as well.

Could it be, that this behavior is set so as the default by the Obsidian Developers? Could it make sense, to have them include usr/bin/local as env for plugins by default instead of adding this in this obsidian git plugin?

Same problem! And is it possible to execute source ~/.zshrc or source ~/.bashrc on Linux or Mac before using git commands? PATH has already set in those files. @Vinzent03

JaheimLee avatar Aug 17 '22 12:08 JaheimLee

Hey, I've added /usr/local/bin to the path for commit,push, pull and fetch. May someone try it? Just repalce the .obsidian/plugins/obsidian-git/main.js with the main.js from the zip. main.zip

Vinzent03 avatar Aug 23 '22 13:08 Vinzent03

I ran into this issue as well, but with a different remote type. My company puts its git installation in a non-standard location, so adding /usr/local/bin wouldn't suffice for my case, and I assume many others would be in the same case. How about adding the option in the plugin settings to specify any directories that need to be added to PATH?

eyuelt avatar Oct 03 '22 04:10 eyuelt

It's available for a month now, I think. You can add custom paths for the PATH env var in the settings now.

Vinzent03 avatar Dec 07 '22 21:12 Vinzent03

Having the same issue here. I was using the plugin without any issue. Suddenly, it stopped working. System: Debian GNU/Linux 12 (bookworm) Obsidian installed as Flatpak.

  • I can commit-push-pull changes via git from terminal. But obsidian plugin says "Cannot run git command"
  • On Flatseal, "/usr/bin" is in Obsidian's PATH. So it should see "/usr/bin/git".
  • From plugin settings, tried adding "PATH=/usr/bin/git" to "Additional PATH environment variable paths". Still, it says "Cannot run git command"

EDIT: It seems like Obsidian-git plugin and Obsidian Zotero Integration plugin are in conflict. When I removed Zotero plugin, the issue resolved. Any idea why they are conflicting? I need to use Zotero plugin actually.

misketmuskat avatar Jan 07 '24 11:01 misketmuskat

It's an issue from the zotero plugin, because it changes the path. https://github.com/mgmeyers/obsidian-zotero-integration/blob/main/src/main.ts#L44C21-L44C21 Please open an issue for that plugin.

Vinzent03 avatar Jan 07 '24 19:01 Vinzent03