Skip to content

Commit 57a46be

Browse files
committed
style: use prettier to format
1 parent 70a6464 commit 57a46be

22 files changed

+1618
-810
lines changed

src/constants.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const DEFAULT_SETTINGS: ObsidianGitSettings = {
1515
listChangedFilesInMessageBody: false,
1616
showStatusBar: true,
1717
updateSubmodules: false,
18-
syncMethod: 'merge',
18+
syncMethod: "merge",
1919
customMessageOnAutoBackup: false,
2020
autoBackupAfterFileChange: false,
2121
treeStructure: false,
@@ -30,13 +30,13 @@ export const DEFAULT_SETTINGS: ObsidianGitSettings = {
3030
};
3131

3232
export const GIT_VIEW_CONFIG = {
33-
type: 'git-view',
34-
name: 'Source Control',
35-
icon: 'git-pull-request'
33+
type: "git-view",
34+
name: "Source Control",
35+
icon: "git-pull-request",
3636
};
3737

3838
export const DIFF_VIEW_CONFIG = {
39-
type: 'diff-view',
40-
name: 'Diff View',
41-
icon: 'git-pull-request'
39+
type: "diff-view",
40+
name: "Diff View",
41+
icon: "git-pull-request",
4242
};

src/gitManager.ts

Lines changed: 77 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { App } from "obsidian";
22
import ObsidianGit from "./main";
3-
import { BranchInfo, FileStatusResult, Status, TreeItem, UnstagedFile } from "./types";
4-
3+
import {
4+
BranchInfo,
5+
FileStatusResult,
6+
Status,
7+
TreeItem,
8+
UnstagedFile,
9+
} from "./types";
510

611
export abstract class GitManager {
712
readonly plugin: ObsidianGit;
@@ -13,29 +18,35 @@ export abstract class GitManager {
1318

1419
abstract status(): Promise<Status>;
1520

16-
abstract commitAll(_: { message: string, status?: Status, unstagedFiles?: UnstagedFile[]; }): Promise<number | undefined>;
21+
abstract commitAll(_: {
22+
message: string;
23+
status?: Status;
24+
unstagedFiles?: UnstagedFile[];
25+
}): Promise<number | undefined>;
1726

1827
abstract commit(message?: string): Promise<number | undefined>;
1928

20-
abstract stageAll(_: { dir?: string, status?: Status; }): Promise<void>;
29+
abstract stageAll(_: { dir?: string; status?: Status }): Promise<void>;
2130

22-
abstract unstageAll(_: { dir?: string, status?: Status; }): Promise<void>;
31+
abstract unstageAll(_: { dir?: string; status?: Status }): Promise<void>;
2332

2433
abstract stage(filepath: string, relativeToVault: boolean): Promise<void>;
2534

2635
abstract unstage(filepath: string, relativeToVault: boolean): Promise<void>;
2736

2837
abstract discard(filepath: string): Promise<void>;
2938

30-
abstract discardAll(_: { dir?: string, status?: Status; }): Promise<void>;
39+
abstract discardAll(_: { dir?: string; status?: Status }): Promise<void>;
3140

3241
abstract pull(): Promise<FileStatusResult[] | undefined>;
3342

3443
abstract push(): Promise<number>;
3544

3645
abstract canPush(): Promise<boolean>;
3746

38-
abstract checkRequirements(): Promise<"valid" | "missing-repo" | "missing-git">;
47+
abstract checkRequirements(): Promise<
48+
"valid" | "missing-repo" | "missing-git"
49+
>;
3950

4051
abstract branchInfo(): Promise<BranchInfo>;
4152

@@ -51,7 +62,10 @@ export abstract class GitManager {
5162

5263
abstract clone(url: string, dir: string, depth?: number): Promise<void>;
5364

54-
abstract setConfig(path: string, value: string | number | boolean | undefined): Promise<void>;
65+
abstract setConfig(
66+
path: string,
67+
value: string | number | boolean | undefined
68+
): Promise<void>;
5569

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

@@ -73,11 +87,13 @@ export abstract class GitManager {
7387

7488
abstract updateBasePath(basePath: string): void;
7589

76-
abstract getDiffString(filePath: string, stagedChanges: boolean): Promise<string>;
90+
abstract getDiffString(
91+
filePath: string,
92+
stagedChanges: boolean
93+
): Promise<string>;
7794

7895
abstract getLastCommitTime(): Promise<Date | undefined>;
7996

80-
8197
getVaultPath(path: string): string {
8298
if (this.plugin.settings.basePath) {
8399
return this.plugin.settings.basePath + "/" + path;
@@ -87,10 +103,15 @@ export abstract class GitManager {
87103
}
88104

89105
getPath(path: string, relativeToVault: boolean): string {
90-
return (relativeToVault && this.plugin.settings.basePath.length > 0) ? path.substring(this.plugin.settings.basePath.length + 1) : path;
106+
return relativeToVault && this.plugin.settings.basePath.length > 0
107+
? path.substring(this.plugin.settings.basePath.length + 1)
108+
: path;
91109
}
92110

93-
private _getTreeStructure(children: FileStatusResult[], beginLength = 0): TreeItem[] {
111+
private _getTreeStructure(
112+
children: FileStatusResult[],
113+
beginLength = 0
114+
): TreeItem[] {
94115
const list: TreeItem[] = [];
95116
children = [...children];
96117
while (children.length > 0) {
@@ -99,22 +120,32 @@ export abstract class GitManager {
99120
if (restPath.contains("/")) {
100121
const title = restPath.substring(0, restPath.indexOf("/"));
101122
const childrenWithSameTitle = children.filter((item) => {
102-
return item.path.substring(beginLength).startsWith(title + "/");
123+
return item.path
124+
.substring(beginLength)
125+
.startsWith(title + "/");
103126
});
104127
childrenWithSameTitle.forEach((item) => children.remove(item));
105-
const path = first.path.substring(0, restPath.indexOf("/") + beginLength);
128+
const path = first.path.substring(
129+
0,
130+
restPath.indexOf("/") + beginLength
131+
);
106132
list.push({
107133
title: title,
108134
path: path,
109135
vaultPath: this.getVaultPath(path),
110-
children: this._getTreeStructure(childrenWithSameTitle, (beginLength > 0 ? (beginLength + title.length) : title.length) + 1)
136+
children: this._getTreeStructure(
137+
childrenWithSameTitle,
138+
(beginLength > 0
139+
? beginLength + title.length
140+
: title.length) + 1
141+
),
111142
});
112143
} else {
113144
list.push({
114145
title: restPath,
115146
statusResult: first,
116147
path: first.path,
117-
vaultPath: this.getVaultPath(first.path)
148+
vaultPath: this.getVaultPath(first.path),
118149
});
119150
children.remove(first);
120151
}
@@ -123,16 +154,24 @@ export abstract class GitManager {
123154
}
124155

125156
/*
126-
* Sorts the children and simplifies the title
127-
* If a node only contains another subdirectory, that subdirectory is moved up one level and integrated into the parent node
128-
*/
157+
* Sorts the children and simplifies the title
158+
* If a node only contains another subdirectory, that subdirectory is moved up one level and integrated into the parent node
159+
*/
129160
private simplify(tree: TreeItem[]): TreeItem[] {
130161
for (const node of tree) {
131162
while (true) {
132163
const singleChild = node.children?.length == 1;
133-
const singleChildIsDir = node.children?.first()?.statusResult == undefined;
134-
135-
if (!(node.children != undefined && singleChild && singleChildIsDir)) break;
164+
const singleChildIsDir =
165+
node.children?.first()?.statusResult == undefined;
166+
167+
if (
168+
!(
169+
node.children != undefined &&
170+
singleChild &&
171+
singleChildIsDir
172+
)
173+
)
174+
break;
136175
const child = node.children.first()!;
137176
node.title += "/" + child.title;
138177
node.statusResult = child.statusResult;
@@ -144,7 +183,9 @@ export abstract class GitManager {
144183
this.simplify(node.children);
145184
}
146185
node.children?.sort((a, b) => {
147-
const dirCompare = (b.statusResult == undefined ? 1 : 0) - (a.statusResult == undefined ? 1 : 0);
186+
const dirCompare =
187+
(b.statusResult == undefined ? 1 : 0) -
188+
(a.statusResult == undefined ? 1 : 0);
148189
if (dirCompare != 0) {
149190
return dirCompare;
150191
} else {
@@ -153,7 +194,9 @@ export abstract class GitManager {
153194
});
154195
}
155196
return tree.sort((a, b) => {
156-
const dirCompare = (b.statusResult == undefined ? 1 : 0) - (a.statusResult == undefined ? 1 : 0);
197+
const dirCompare =
198+
(b.statusResult == undefined ? 1 : 0) -
199+
(a.statusResult == undefined ? 1 : 0);
157200
if (dirCompare != 0) {
158201
return dirCompare;
159202
} else {
@@ -182,9 +225,9 @@ export abstract class GitManager {
182225
}
183226

184227
if (template.includes("{{files}}")) {
185-
status = status ?? await this.status();
228+
status = status ?? (await this.status());
186229

187-
const changeset: { [key: string]: string[]; } = {};
230+
const changeset: { [key: string]: string[] } = {};
188231
status.staged.forEach((value: FileStatusResult) => {
189232
if (value.index in changeset) {
190233
changeset[value.index].push(value.path);
@@ -209,7 +252,14 @@ export abstract class GitManager {
209252
moment().format(this.plugin.settings.commitDateFormat)
210253
);
211254
if (this.plugin.settings.listChangedFilesInMessageBody) {
212-
template = template + "\n\n" + "Affected files:" + "\n" + (status ?? await this.status()).staged.map((e) => e.path).join("\n");
255+
template =
256+
template +
257+
"\n\n" +
258+
"Affected files:" +
259+
"\n" +
260+
(status ?? (await this.status())).staged
261+
.map((e) => e.path)
262+
.join("\n");
213263
}
214264
return template;
215265
}

0 commit comments

Comments
 (0)