Skip to content

Commit

Permalink
fix: use correct git path on clone on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Mar 7, 2023
1 parent fdde0bf commit 686c323
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,23 @@ export default class ObsidianGit extends Plugin {
}
}
new Notice(`Cloning new repo into "${dir}"`);
await this.gitManager.clone(url, dir, depthInt);
const oldBase = this.settings.basePath;
const customDir = dir && dir !== ".";
//Set new base path before clone to ensure proper .git/index file location in isomorphic-git
if (customDir) {
this.settings.basePath = dir;
}
try {
await this.gitManager.clone(url, dir, depthInt);
} catch (error) {
this.settings.basePath = oldBase;
this.saveSettings();
throw error;
}
new Notice("Cloned new repo.");
new Notice("Please restart Obsidian");

if (dir && dir !== ".") {
this.settings.basePath = dir;
if (customDir) {
this.saveSettings();
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/myAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ export class MyAdapter {
index: any;
indexctime: number | undefined;
indexmtime: number | undefined;
lastBasePath: string | undefined;

constructor(vault: Vault, private readonly plugin: ObsidianGit) {
this.adapter = vault.adapter;
this.vault = vault;
this.lastBasePath = this.plugin.settings.basePath;

this.promises.readFile = this.readFile.bind(this);
this.promises.writeFile = this.writeFile.bind(this);
Expand All @@ -36,6 +39,11 @@ export class MyAdapter {
}
} else {
if (path.endsWith(this.gitDir + "/index")) {
if (this.plugin.settings.basePath != this.lastBasePath) {
this.clearIndex();
this.lastBasePath = this.plugin.settings.basePath;
return this.adapter.readBinary(path);
}
return this.index ?? this.adapter.readBinary(path);
}
const file = this.vault.getAbstractFileByPath(path);
Expand Down Expand Up @@ -183,6 +191,10 @@ export class MyAdapter {
}
);
}
this.clearIndex();
}

clearIndex() {
this.index = undefined;
this.indexctime = undefined;
this.indexmtime = undefined;
Expand Down

0 comments on commit 686c323

Please sign in to comment.