@@ -182,6 +182,8 @@ export class SimpleGit extends GitManager {
182
182
const relPluginConfigDir =
183
183
this . app . vault . configDir + "/plugins/obsidian-git/" ;
184
184
185
+ await this . addAskPassScriptToExclude ( ) ;
186
+
185
187
await fsPromises . writeFile (
186
188
path . join ( absPluginConfigPath , ASK_PASS_SCRIPT_FILE ) ,
187
189
ASK_PASS_SCRIPT
@@ -244,6 +246,56 @@ export class SimpleGit extends GitManager {
244
246
}
245
247
}
246
248
249
+ /**
250
+ * Adds the askpass script to the exclude file of the git repository.
251
+ *
252
+ * This prevents the script from being tracked by git. This should be no
253
+ * problem as the script does not contain any sensitive data, but may
254
+ * cause issues with file permissions on other devices.
255
+ * See https://github.com/Vinzent03/obsidian-git/issues/903
256
+ */
257
+ async addAskPassScriptToExclude ( ) : Promise < void > {
258
+ try {
259
+ const absoluteExcludeFilePath = await this . git . revparse ( [
260
+ "--path-format=absolute" ,
261
+ "--git-path" ,
262
+ "info/exclude" ,
263
+ ] ) ;
264
+
265
+ const vaultRelativeAskPassScriptFile = path . join (
266
+ this . app . vault . configDir ,
267
+ "plugins" ,
268
+ "obsidian-git" ,
269
+ ASK_PASS_SCRIPT_FILE
270
+ ) ;
271
+ const repoRelativeAskPassScriptFile = this . getRelativeRepoPath (
272
+ vaultRelativeAskPassScriptFile ,
273
+ true
274
+ ) ;
275
+
276
+ const content = await fsPromises . readFile (
277
+ absoluteExcludeFilePath ,
278
+ "utf-8"
279
+ ) ;
280
+ const lines = content . split ( "\n" ) ;
281
+ const contains = lines . some ( ( line ) =>
282
+ line . contains ( repoRelativeAskPassScriptFile )
283
+ ) ;
284
+ if ( ! contains ) {
285
+ await fsPromises . appendFile (
286
+ absoluteExcludeFilePath ,
287
+ repoRelativeAskPassScriptFile + "\n"
288
+ ) ;
289
+ }
290
+ } catch ( error ) {
291
+ // Catch any errors, because this is not critical
292
+ console . error (
293
+ "Error while adding askpass script to exclude file:" ,
294
+ error
295
+ ) ;
296
+ }
297
+ }
298
+
247
299
unload ( ) : void {
248
300
this . watchAbortController ?. abort ( ) ;
249
301
}
0 commit comments