Skip to content

Commit 686c323

Browse files
committed
fix: use correct git path on clone on mobile
1 parent fdde0bf commit 686c323

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/main.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,23 @@ export default class ObsidianGit extends Plugin {
781781
}
782782
}
783783
new Notice(`Cloning new repo into "${dir}"`);
784-
await this.gitManager.clone(url, dir, depthInt);
784+
const oldBase = this.settings.basePath;
785+
const customDir = dir && dir !== ".";
786+
//Set new base path before clone to ensure proper .git/index file location in isomorphic-git
787+
if (customDir) {
788+
this.settings.basePath = dir;
789+
}
790+
try {
791+
await this.gitManager.clone(url, dir, depthInt);
792+
} catch (error) {
793+
this.settings.basePath = oldBase;
794+
this.saveSettings();
795+
throw error;
796+
}
785797
new Notice("Cloned new repo.");
786798
new Notice("Please restart Obsidian");
787799

788-
if (dir && dir !== ".") {
789-
this.settings.basePath = dir;
800+
if (customDir) {
790801
this.saveSettings();
791802
}
792803
}

src/myAdapter.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ export class MyAdapter {
88
index: any;
99
indexctime: number | undefined;
1010
indexmtime: number | undefined;
11+
lastBasePath: string | undefined;
12+
1113
constructor(vault: Vault, private readonly plugin: ObsidianGit) {
1214
this.adapter = vault.adapter;
1315
this.vault = vault;
16+
this.lastBasePath = this.plugin.settings.basePath;
1417

1518
this.promises.readFile = this.readFile.bind(this);
1619
this.promises.writeFile = this.writeFile.bind(this);
@@ -36,6 +39,11 @@ export class MyAdapter {
3639
}
3740
} else {
3841
if (path.endsWith(this.gitDir + "/index")) {
42+
if (this.plugin.settings.basePath != this.lastBasePath) {
43+
this.clearIndex();
44+
this.lastBasePath = this.plugin.settings.basePath;
45+
return this.adapter.readBinary(path);
46+
}
3947
return this.index ?? this.adapter.readBinary(path);
4048
}
4149
const file = this.vault.getAbstractFileByPath(path);
@@ -183,6 +191,10 @@ export class MyAdapter {
183191
}
184192
);
185193
}
194+
this.clearIndex();
195+
}
196+
197+
clearIndex() {
186198
this.index = undefined;
187199
this.indexctime = undefined;
188200
this.indexmtime = undefined;

0 commit comments

Comments
 (0)