Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug fix] Allow commiting of files large than 100mb if handled by LFS #822

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions src/gitManager/simpleGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,25 @@ export class SimpleGit extends GitManager {
}
throw error;
}

async isFileTrackedByLFS(filePath: string): Promise<boolean> {
try {
// Checks if Gits filter attribute is set to lfs for the file, which means it is (or will be) tracked by LFS.
const result = await this.git.raw([
"check-attr",
"filter",
filePath,
]);
return result.includes("filter: lfs");
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : String(error);
this.plugin.displayError(
`Error checking LFS status: ${errorMessage}`
);
return false;
}
}
}

export const zeroCommit: BlameCommit = {
Expand Down
22 changes: 18 additions & 4 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { TFile } from "obsidian";
import { CONFLICT_OUTPUT_FILE } from "./constants";
import type ObsidianGit from "./main";
import { splitRemoteBranch } from "./utils";
import { SimpleGit } from "./gitManager/simpleGit";

export default class Tools {
constructor(private readonly plugin: ObsidianGit) {}
Expand All @@ -17,15 +18,28 @@ export default class Tools {

//Check for files >100mb on GitHub remote
if (remoteUrl?.includes("github.com")) {
const tooBigFiles = files.filter((f) => {
const tooBigFiles = [];

for (const f of files) {
const file = this.plugin.app.vault.getAbstractFileByPath(
f.vault_path
);
if (file instanceof TFile) {
return file.stat.size >= 100000000;
const isFileTrackedByLfs =
this.plugin.gitManager instanceof SimpleGit
? await this.plugin.gitManager.isFileTrackedByLFS(
f.vault_path
)
: false;
if (
file.stat.size >= 100000000 &&
!isFileTrackedByLfs
) {
tooBigFiles.push(f);
}
}
return false;
});
}

if (tooBigFiles.length > 0) {
this.plugin.displayError(
`Did not commit, because following files are too big: ${tooBigFiles
Expand Down
Loading