Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinzent03 committed Oct 10, 2024
1 parent 6076c25 commit 0fd311f
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 132 deletions.
13 changes: 12 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ export default tseslint.config(
},
},
rules: {
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-unused-vars": [
"error",
{
args: "all",
argsIgnorePattern: "^_",
caughtErrors: "all",
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
varsIgnorePattern: "^_",
ignoreRestSiblings: true,
},
],
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dev": "node esbuild.config.mjs dev",
"build": "node esbuild.config.mjs production",
"release": "standard-version",
"lint": "eslint",
"lint": "eslint src",
"format": "prettier --check src",
"tsc": "tsc --noEmit",
"svelte": "svelte-check",
Expand Down
5 changes: 1 addition & 4 deletions src/automaticsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class AutomaticsManager {
}

async init() {
this.setUpAutoCommitAndSync();
await this.setUpAutoCommitAndSync();
const lastAutos = this.loadLastAuto();

if (
Expand Down Expand Up @@ -155,7 +155,6 @@ export default class AutomaticsManager {
}
});
this.saveLastAuto(new Date(), "backup");
this.plugin.saveSettings();
this.startAutoCommitAndSync();
}

Expand All @@ -169,7 +168,6 @@ export default class AutomaticsManager {
this.plugin.pullChangesFromRemote()
);
this.saveLastAuto(new Date(), "pull");
this.plugin.saveSettings();
this.startAutoPull();
}, time);
}
Expand All @@ -182,7 +180,6 @@ export default class AutomaticsManager {
this.timeoutIDPush = window.setTimeout(() => {
this.plugin.promiseQueue.addTask(() => this.plugin.push());
this.saveLastAuto(new Date(), "push");
this.plugin.saveSettings();
this.startAutoPush();
}, time);
}
Expand Down
22 changes: 12 additions & 10 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export function addCommmands(plugin: ObsidianGit) {
callback: async () => {
const path = plugin.gitManager.getRelativeVaultPath(".gitignore");
if (!(await app.vault.adapter.exists(path))) {
app.vault.adapter.write(path, "");
await app.vault.adapter.write(path, "");
}
const content = await app.vault.adapter.read(path);
const modal = new IgnoreModal(app, content);
const res = await modal.open();
if (res !== undefined) {
await app.vault.adapter.write(path, res);
plugin.refresh();
await plugin.refresh();
}
},
});
Expand All @@ -50,7 +50,7 @@ export function addCommmands(plugin: ObsidianGit) {
} else {
leaf = leafs.first()!;
}
app.workspace.revealLeaf(leaf);
await app.workspace.revealLeaf(leaf);
},
});
plugin.addCommand({
Expand All @@ -71,7 +71,7 @@ export function addCommmands(plugin: ObsidianGit) {
} else {
leaf = leafs.first()!;
}
app.workspace.revealLeaf(leaf);
await app.workspace.revealLeaf(leaf);
},
});

Expand All @@ -83,7 +83,7 @@ export function addCommmands(plugin: ObsidianGit) {
if (checking) {
return file !== null;
} else {
getNewLeaf(app)?.setViewState({
void getNewLeaf(app)?.setViewState({
type: DIFF_VIEW_CONFIG.type,
active: true,
state: {
Expand Down Expand Up @@ -142,7 +142,9 @@ export function addCommmands(plugin: ObsidianGit) {
if (checking) {
return file !== null;
} else {
plugin.addFileToGitignore(file!);
plugin
.addFileToGitignore(file!)
.catch((e) => plugin.displayError(e));
}
},
});
Expand Down Expand Up @@ -310,7 +312,7 @@ export function addCommmands(plugin: ObsidianGit) {
"Successfully deleted repository. Reloading plugin..."
);
plugin.unloadPlugin();
plugin.init();
await plugin.init();
}
} else {
new Notice("No repository found");
Expand Down Expand Up @@ -352,23 +354,23 @@ export function addCommmands(plugin: ObsidianGit) {
id: "switch-branch",
name: "Switch branch",
callback: () => {
plugin.switchBranch();
plugin.switchBranch().catch((e) => plugin.displayError(e));
},
});

plugin.addCommand({
id: "create-branch",
name: "Create new branch",
callback: () => {
plugin.createBranch();
plugin.createBranch().catch((e) => plugin.displayError(e));
},
});

plugin.addCommand({
id: "delete-branch",
name: "Delete branch",
callback: () => {
plugin.deleteBranch();
plugin.deleteBranch().catch((e) => plugin.displayError(e));
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/gitManager/gitManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export abstract class GitManager {
value: string | number | boolean | undefined
): Promise<void>;

abstract getConfig(path: string): Promise<any>;
abstract getConfig(path: string): Promise<string>;

abstract fetch(remote?: string): Promise<void>;

Expand Down
14 changes: 11 additions & 3 deletions src/gitManager/simpleGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,19 +716,27 @@ export class SimpleGit extends GitManager {
);
}

async setConfig(path: string, value: any): Promise<void> {
async setConfig(path: string, value: string): Promise<void> {
if (value == undefined) {
await this.git.raw(["config", "--local", "--unset", path]);
} else {
await this.git.addConfig(path, value, (err) => this.onError(err));
}
}

async getConfig(path: string): Promise<any> {
async getConfig(path: string): Promise<string> {
const config = await this.git.listConfig("local", (err) =>
this.onError(err)
);
return config.all[path];
const res = config.all[path];
if (typeof res === "string") {
return res;
} else {
const error = new Error("Config value is not a string");

this.onError(error);
throw error;
}
}

async fetch(remote?: string): Promise<void> {
Expand Down
Loading

0 comments on commit 0fd311f

Please sign in to comment.