Skip to content

Commit 0ce9ac3

Browse files
committed
feat: list filenames affected by commit in the commit body
close #3
1 parent e992199 commit 0ce9ac3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

main.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface ObsidianGitSettings {
1818
disablePush: boolean;
1919
pullBeforePush: boolean;
2020
disablePopups: boolean;
21+
listChangedFilesInMessageBody: boolean;
2122
}
2223
const DEFAULT_SETTINGS: ObsidianGitSettings = {
2324
commitMessage: "vault backup: {{date}}",
@@ -27,6 +28,7 @@ const DEFAULT_SETTINGS: ObsidianGitSettings = {
2728
disablePush: false,
2829
pullBeforePush: true,
2930
disablePopups: false,
31+
listChangedFilesInMessageBody: false,
3032
};
3133

3234
export default class ObsidianGit extends Plugin {
@@ -219,7 +221,10 @@ export default class ObsidianGit extends Plugin {
219221

220222
async commit(message?: string): Promise<void> {
221223
this.setState(PluginState.commit);
222-
const commitMessage = message ?? await this.formatCommitMessage(this.settings.commitMessage);
224+
let commitMessage: string | string[] = message ?? await this.formatCommitMessage(this.settings.commitMessage);
225+
if (this.settings.listChangedFilesInMessageBody) {
226+
commitMessage = [commitMessage, "Affected files:", (await this.git.status()).staged.join("\n")];
227+
}
223228
await this.git.commit(commitMessage);
224229
}
225230

@@ -403,6 +408,17 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
403408
})
404409
);
405410

411+
new Setting(containerEl)
412+
.setName("List filenames affected by commit in the commit body")
413+
.addToggle((toggle) =>
414+
toggle
415+
.setValue(plugin.settings.listChangedFilesInMessageBody)
416+
.onChange((value) => {
417+
plugin.settings.listChangedFilesInMessageBody = value;
418+
plugin.saveSettings();
419+
})
420+
);
421+
406422
new Setting(containerEl)
407423
.setName("Current branch")
408424
.setDesc("Switch to a different branch")

0 commit comments

Comments
 (0)