Skip to content

Commit

Permalink
fix: check for too big files in source control view
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Jul 20, 2022
1 parent 150d11f commit 2275d4f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { DEFAULT_SETTINGS, DIFF_VIEW_CONFIG, GIT_VIEW_CONFIG } from "./constants
import { GitManager } from "./gitManager";
import { openHistoryInGitHub, openLineInGitHub } from "./openInGitHub";
import { SimpleGit } from "./simpleGit";
import { ObsidianGitSettings, PluginState, Status } from "./types";
import { FileStatusResult, ObsidianGitSettings, PluginState, Status } from "./types";
import DiffView from "./ui/diff/diffView";
import { GeneralModal } from "./ui/modals/generalModal";
import GitView from "./ui/sidebar/sidebarView";
Expand Down Expand Up @@ -427,7 +427,7 @@ export default class ObsidianGit extends Plugin {
status = await this.gitManager.status();
}

if (await this.hasTooBigFiles(status)) {
if (await this.hasTooBigFiles([...status.staged, ...status.changed])) {
this.setState(PluginState.idle);
return false;
}
Expand Down Expand Up @@ -460,7 +460,7 @@ export default class ObsidianGit extends Plugin {
return true;
}

async hasTooBigFiles(status: Status): Promise<boolean> {
async hasTooBigFiles(files: FileStatusResult[]): Promise<boolean> {
const branchInfo = await this.gitManager.branchInfo();
const remote = branchInfo.tracking?.split("/")[0];

Expand All @@ -470,7 +470,7 @@ export default class ObsidianGit extends Plugin {
//Check for files >100mb on GitHub remote
if (remoteUrl.includes("github.com")) {

const tooBigFiles = [...status.staged, ...status.changed].filter(f => {
const tooBigFiles = files.filter(f => {
const file = this.app.vault.getAbstractFileByPath(f.vault_path);
if (file instanceof TFile) {
return file.stat.size >= 100000000;
Expand Down
12 changes: 9 additions & 3 deletions src/ui/sidebar/gitView.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { debounce, EventRef, MetadataCache, setIcon } from "obsidian";
import ObsidianGit from "src/main";
import { Status, TreeItem } from "src/types";
import { PluginState, Status, TreeItem } from "src/types";
import { onDestroy } from "svelte";
import { slide } from "svelte/transition";
import FileComponent from "./components/fileComponent.svelte";
Expand Down Expand Up @@ -40,8 +40,14 @@
onDestroy(() => {
removeEventListener("git-view-refresh", refresh);
});
function commit() {
async function commit() {
loading = true;
if (await plugin.hasTooBigFiles(status.staged)) {
plugin.setState(PluginState.idle);
return false;
}
plugin.gitManager
.commit(commitMessage)
.then(() => {
Expand All @@ -67,7 +73,7 @@
loading = plugin.loading;
}
function triggerRefresh(){
function triggerRefresh() {
dispatchEvent(new CustomEvent("git-refresh"));
}
Expand Down

0 comments on commit 2275d4f

Please sign in to comment.