I spent two days trying to figure this out. But I’m very new to typescript and plugin development.
I want to fetch the logs of my vault stored in git using isomorphic-git (because it allegedly works on mobile too).
Here is what I came up with so far, simply extending the sample plugin:
import * as git from 'isomorphic-git';
async onload() {
this.addCommand({
id: 'output-git-log',
name: 'Output Git Log',
callback: () => this.outputGitLog(),
});
async outputGitLog() {
const dir = this.app.vault.getRoot().path;
const log = await git.log({ fs: this.app.vault.adapter, dir });
}
This is the error I’m getting:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'bind')
at bindFs (plugin:sample-plugin:8477:68)
at new FileSystem (plugin:sample-plugin:8497:7)
at log (plugin:sample-plugin:8997:11)
at MyPlugin.outputGitLog (plugin:sample-plugin:9075:24)
at Object.callback (plugin:sample-plugin:9057:28)
at pj (app.js:1:1965818)
at t.onChooseItem (app.js:1:2612161)
at t.onChooseSuggestion (app.js:1:1795118)
at t.selectSuggestion (app.js:1:1794588)
at e.useSelectedItem (app.js:1:1378259)
It seems to me that the file system does not support bind(). I looked into the source of obsidian-git and as far as I can tell it uses vault.adapter with isomorphic-git:
Vinzent03/obsidian-git/blob/d2991ccedcd59c56e685c2c776159f236bad8331/src/gitManager/myAdapter.ts#L23C24-L23C37
I experimented with LightningFS too, trying to follow the instructions on the homepage of isomorphic-git. Didn’t succeed with that either.
Please can someone shed a light on what I am doing wrong? I am out of ideas and also lacking enough knowledge.
The error Cannot read properties of undefined suggests to me that this.app.vault.adapter is undefined when the plugin is trying to bind the file system. Why is that?
I didn’t look into it too deep but from the first look I don’t see the “fs” parameter in the available parameters for the log function. where are you getting that?
from the code you shared you’re trying to access the git variable and only then call the log command , but the git variable is exclusively an instance of simple git meant for desktop
if you want to call isomorphic git wrapper comman, you should emit the git variable
and this way you’re just calling the wrapper function and then the original isomorphic git function is being handled inside the log function you’re calling
gitManager is a custom wrapper for isomorphic-git and simplegit in the plugin obsidian-git. I don’t need all that, I just want to use isomorphic-git plainly.
okay, then the things i said dont matter, and you dont need any dependencies on the git plugin at all, but you lose this benefit i mentioned:
handle all git operations through git plugin, so that if user has some custom git config, they don’t have to configure each plugin separately
but most users probably wont change their git repo configurations.
I think that it’s still easier to work with isomorphic git through the obsidian git plugin but if you don’t want that then I probably can’t help much because I have no experience with isomorphic git