Skip to content

Commit 655d171

Browse files
committed
fix: add obsidian_askpass.sh to .git/info/exclude
close #903
1 parent e15cdc0 commit 655d171

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/gitManager/simpleGit.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ export class SimpleGit extends GitManager {
182182
const relPluginConfigDir =
183183
this.app.vault.configDir + "/plugins/obsidian-git/";
184184

185+
await this.addAskPassScriptToExclude();
186+
185187
await fsPromises.writeFile(
186188
path.join(absPluginConfigPath, ASK_PASS_SCRIPT_FILE),
187189
ASK_PASS_SCRIPT
@@ -244,6 +246,56 @@ export class SimpleGit extends GitManager {
244246
}
245247
}
246248

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+
247299
unload(): void {
248300
this.watchAbortController?.abort();
249301
}

0 commit comments

Comments
 (0)