Skip to content

Commit

Permalink
refactor: Use boolean values for getConflict() and setConflict()
Browse files Browse the repository at this point in the history
  • Loading branch information
injust committed Dec 16, 2023
1 parent 1d81577 commit aa0dca5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/gitManager/isomorphicGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ export class IsomorphicGit extends GitManager {
await this.checkAuthorInfo();
this.plugin.setState(PluginState.commit);
const formatMessage = await this.formatCommitMessage(message);
const hadConflict =
this.plugin.localStorage.getConflict() === "true";
const hadConflict = this.plugin.localStorage.getConflict();
let parent: string[] | undefined = undefined;

if (hadConflict) {
Expand All @@ -220,7 +219,7 @@ export class IsomorphicGit extends GitManager {
parent: parent,
})
);
this.plugin.localStorage.setConflict("false");
this.plugin.localStorage.setConflict(false);
return;
} catch (error) {
this.plugin.displayError(error);
Expand Down
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ export default class ObsidianGit extends Plugin {
}): Promise<boolean> {
if (!(await this.isAllInitialized())) return false;

let hadConflict = this.localStorage.getConflict() === "true";
let hadConflict = this.localStorage.getConflict();

let changedFiles: { vault_path: string }[];
let status: Status | undefined;
Expand All @@ -1016,7 +1016,7 @@ export default class ObsidianGit extends Plugin {

//Should not be necessary, but just in case
if (status.conflicted.length == 0) {
this.localStorage.setConflict("false");
this.localStorage.setConflict(false);
hadConflict = false;
}

Expand Down Expand Up @@ -1106,7 +1106,7 @@ export default class ObsidianGit extends Plugin {
//Handle resolved conflict after commit
if (this.gitManager instanceof SimpleGit) {
if ((await this.updateCachedStatus()).conflicted.length == 0) {
this.localStorage.setConflict("false");
this.localStorage.setConflict(false);
}
}

Expand Down Expand Up @@ -1169,7 +1169,7 @@ export default class ObsidianGit extends Plugin {
if (!(await this.remotesAreSet())) {
return false;
}
const hadConflict = this.localStorage.getConflict() === "true";
const hadConflict = this.localStorage.getConflict();
if (this.gitManager instanceof SimpleGit)
await this.mayDeleteConflictFile();

Expand Down Expand Up @@ -1550,7 +1550,7 @@ export default class ObsidianGit extends Plugin {
async handleConflict(conflicted?: string[]): Promise<void> {
this.setState(PluginState.conflicted);

this.localStorage.setConflict("true");
this.localStorage.setConflict(true);
let lines: string[] | undefined;
if (conflicted !== undefined) {
lines = [
Expand Down
8 changes: 4 additions & 4 deletions src/setting/localStorageSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ export class LocalStorageSettings {
return app.saveLocalStorage(this.prefix + "hostname", value);
}

getConflict(): string | null {
return app.loadLocalStorage(this.prefix + "conflict");
getConflict(): boolean {
return app.loadLocalStorage(this.prefix + "conflict") == "true";
}

setConflict(value: string): void {
return app.saveLocalStorage(this.prefix + "conflict", value);
setConflict(value: boolean): void {
return app.saveLocalStorage(this.prefix + "conflict", `${value}`);
}

getLastAutoPull(): string | null {
Expand Down

0 comments on commit aa0dca5

Please sign in to comment.