Skip to content

Commit 20c942e

Browse files
JKluckowVinzent03
andauthored
feat: allow empty default manual commit message (#1022)
* feat: Allow empty commit message setting to require manual input - Allow the "Commit message on manual commit" setting to remain empty instead of automatically falling back to the default value - Add a "Default" button to restore the default value when needed - Abort commit with a notice when no commit message is configured and none is provided manually * refactor: use icon button and change text instead of new display --------- Co-authored-by: Vinzent <[email protected]>
1 parent bde2b3d commit 20c942e

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/main.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,16 @@ export default class ObsidianGit extends Plugin {
996996
cmtMessage = res.stdout;
997997
}
998998
}
999+
1000+
// Check if commit message is empty after all processing
1001+
if (!cmtMessage || cmtMessage.trim() === "") {
1002+
new Notice("Commit aborted: No commit message provided");
1003+
this.setPluginState({
1004+
gitAction: CurrentGitAction.idle,
1005+
});
1006+
return false;
1007+
}
1008+
9991009
let committedFiles: number | undefined;
10001010
if (onlyStaged) {
10011011
committedFiles = await this.gitManager.commit({

src/setting/settings.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -282,29 +282,30 @@ export class ObsidianGitSettingsTab extends PluginSettingTab {
282282

283283
new Setting(containerEl).setName("Commit message").setHeading();
284284

285-
new Setting(containerEl)
285+
const manualCommitMessageSetting = new Setting(containerEl)
286286
.setName("Commit message on manual commit")
287287
.setDesc(
288288
"Available placeholders: {{date}}" +
289-
" (see below), {{hostname}} (see below), {{numFiles}} (number of changed files in the commit) and {{files}} (changed files in commit message)."
290-
)
291-
.addTextArea((text) => {
292-
text.setPlaceholder(
293-
DEFAULT_SETTINGS.commitMessage
294-
).onChange(async (value) => {
295-
if (value === "") {
296-
plugin.settings.commitMessage =
297-
DEFAULT_SETTINGS.commitMessage;
298-
} else {
299-
plugin.settings.commitMessage = value;
300-
}
301-
await plugin.saveSettings();
302-
});
303-
this.setNonDefaultValue({
304-
text,
305-
settingsProperty: "commitMessage",
306-
});
289+
" (see below), {{hostname}} (see below), {{numFiles}} (number of changed files in the commit) and {{files}} (changed files in commit message). Leave empty to require manual input on each commit."
290+
);
291+
manualCommitMessageSetting.addTextArea((text) => {
292+
manualCommitMessageSetting.addButton((button) => {
293+
button
294+
.setIcon("reset")
295+
.setTooltip(
296+
`Set to default: "${DEFAULT_SETTINGS.commitMessage}"`
297+
)
298+
.onClick(() => {
299+
text.setValue(DEFAULT_SETTINGS.commitMessage);
300+
text.onChanged();
301+
});
307302
});
303+
text.setValue(plugin.settings.commitMessage);
304+
text.onChange(async (value) => {
305+
plugin.settings.commitMessage = value;
306+
await plugin.saveSettings();
307+
});
308+
});
308309

309310
new Setting(containerEl)
310311
.setName("Commit message script")

0 commit comments

Comments
 (0)