File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -781,12 +781,23 @@ export default class ObsidianGit extends Plugin {
781
781
}
782
782
}
783
783
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
+ }
785
797
new Notice ( "Cloned new repo." ) ;
786
798
new Notice ( "Please restart Obsidian" ) ;
787
799
788
- if ( dir && dir !== "." ) {
789
- this . settings . basePath = dir ;
800
+ if ( customDir ) {
790
801
this . saveSettings ( ) ;
791
802
}
792
803
}
Original file line number Diff line number Diff line change @@ -8,9 +8,12 @@ export class MyAdapter {
8
8
index : any ;
9
9
indexctime : number | undefined ;
10
10
indexmtime : number | undefined ;
11
+ lastBasePath : string | undefined ;
12
+
11
13
constructor ( vault : Vault , private readonly plugin : ObsidianGit ) {
12
14
this . adapter = vault . adapter ;
13
15
this . vault = vault ;
16
+ this . lastBasePath = this . plugin . settings . basePath ;
14
17
15
18
this . promises . readFile = this . readFile . bind ( this ) ;
16
19
this . promises . writeFile = this . writeFile . bind ( this ) ;
@@ -36,6 +39,11 @@ export class MyAdapter {
36
39
}
37
40
} else {
38
41
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
+ }
39
47
return this . index ?? this . adapter . readBinary ( path ) ;
40
48
}
41
49
const file = this . vault . getAbstractFileByPath ( path ) ;
@@ -183,6 +191,10 @@ export class MyAdapter {
183
191
}
184
192
) ;
185
193
}
194
+ this . clearIndex ( ) ;
195
+ }
196
+
197
+ clearIndex ( ) {
186
198
this . index = undefined ;
187
199
this . indexctime = undefined ;
188
200
this . indexmtime = undefined ;
You can’t perform that action at this time.
0 commit comments