Skip to content

Commit

Permalink
feat: list filenames affected by commit in the commit body
Browse files Browse the repository at this point in the history
close #3
  • Loading branch information
Vinzent03 committed Mar 15, 2021
1 parent e992199 commit 0ce9ac3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface ObsidianGitSettings {
disablePush: boolean;
pullBeforePush: boolean;
disablePopups: boolean;
listChangedFilesInMessageBody: boolean;
}
const DEFAULT_SETTINGS: ObsidianGitSettings = {
commitMessage: "vault backup: {{date}}",
Expand All @@ -27,6 +28,7 @@ const DEFAULT_SETTINGS: ObsidianGitSettings = {
disablePush: false,
pullBeforePush: true,
disablePopups: false,
listChangedFilesInMessageBody: false,
};

export default class ObsidianGit extends Plugin {
Expand Down Expand Up @@ -219,7 +221,10 @@ export default class ObsidianGit extends Plugin {

async commit(message?: string): Promise<void> {
this.setState(PluginState.commit);
const commitMessage = message ?? await this.formatCommitMessage(this.settings.commitMessage);
let commitMessage: string | string[] = message ?? await this.formatCommitMessage(this.settings.commitMessage);
if (this.settings.listChangedFilesInMessageBody) {
commitMessage = [commitMessage, "Affected files:", (await this.git.status()).staged.join("\n")];
}
await this.git.commit(commitMessage);
}

Expand Down Expand Up @@ -403,6 +408,17 @@ class ObsidianGitSettingsTab extends PluginSettingTab {
})
);

new Setting(containerEl)
.setName("List filenames affected by commit in the commit body")
.addToggle((toggle) =>
toggle
.setValue(plugin.settings.listChangedFilesInMessageBody)
.onChange((value) => {
plugin.settings.listChangedFilesInMessageBody = value;
plugin.saveSettings();
})
);

new Setting(containerEl)
.setName("Current branch")
.setDesc("Switch to a different branch")
Expand Down

0 comments on commit 0ce9ac3

Please sign in to comment.