Skip to content

Commit 0754fd8

Browse files
committed
fix: check file size for non Obsidian files as well
close #859
1 parent 15416cb commit 0754fd8

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

src/tools.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,45 @@ export default class Tools {
2828
if (remoteUrl?.includes("github.com")) {
2929
const tooBigFiles = [];
3030

31+
const gitManager = this.plugin.gitManager;
3132
for (const f of files) {
3233
const file = this.plugin.app.vault.getAbstractFileByPath(
3334
f.vaultPath
3435
);
36+
let over100mb = false;
37+
3538
if (file instanceof TFile) {
39+
// Prefer the cached file size if available
3640
if (file.stat.size >= 100000000) {
37-
const gitManager = this.plugin.gitManager;
38-
let isFileTrackedByLfs = false;
39-
if (gitManager instanceof SimpleGit) {
40-
isFileTrackedByLfs =
41-
await gitManager.isFileTrackedByLFS(f.path);
42-
}
43-
if (!isFileTrackedByLfs) {
44-
tooBigFiles.push(f);
45-
}
41+
over100mb = true;
42+
}
43+
} else {
44+
const statRes = await this.plugin.app.vault.adapter.stat(
45+
f.vaultPath
46+
);
47+
if (statRes && statRes.size >= 100000000) {
48+
over100mb = true;
49+
}
50+
}
51+
if (over100mb) {
52+
let isFileTrackedByLfs = false;
53+
if (gitManager instanceof SimpleGit) {
54+
isFileTrackedByLfs =
55+
await gitManager.isFileTrackedByLFS(f.path);
56+
}
57+
if (!isFileTrackedByLfs) {
58+
tooBigFiles.push(f);
4659
}
4760
}
4861
}
4962

5063
if (tooBigFiles.length > 0) {
5164
this.plugin.displayError(
52-
`Did not commit, because following files are too big: ${tooBigFiles
65+
`Aborted commit, because the following files are too big:\n- ${tooBigFiles
5366
.map((e) => e.vaultPath)
54-
.join("\n")}. Please remove them.`
67+
.join(
68+
"\n- "
69+
)}\nPlease remove them or add to .gitignore.`
5570
);
5671

5772
return true;

0 commit comments

Comments
 (0)