Skip to content

Commit d2e1954

Browse files
Add discard all changes command (#446)
* Add reset-hard command * Update placeholder text * Rename and refactor * Remove dir parameter
1 parent a55ff5d commit d2e1954

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,23 @@ export default class ObsidianGit extends Plugin {
379379
}
380380
});
381381

382+
this.addCommand({
383+
id: "discard-all",
384+
name: "CAUTION: Discard all changes",
385+
callback: async () => {
386+
if (! await this.isAllInitialized()) return false;
387+
const modal = new GeneralModal({
388+
options: ["NO", "YES"],
389+
placeholder: "Do you want to discard all changes to tracked files? This action cannot be undone.",
390+
onlySelection: true
391+
});
392+
const shouldDiscardAll = await modal.open() === "YES";
393+
if (shouldDiscardAll) {
394+
this.promiseQueue.addTask(() => this.discardAll());
395+
}
396+
}
397+
});
398+
382399
this.registerEvent(
383400
this.app.workspace.on('file-menu', (menu, file, source) => {
384401
this.handleFileMenu(menu, file, source);
@@ -1068,6 +1085,13 @@ export default class ObsidianGit extends Plugin {
10681085
}
10691086
}
10701087

1088+
async discardAll() {
1089+
await this.gitManager.discardAll({
1090+
status: this.cachedStatus
1091+
})
1092+
new Notice('All local changes have been discarded. New files remain untouched.');
1093+
}
1094+
10711095
clearAutos(): void {
10721096
this.clearAutoBackup();
10731097
this.clearAutoPush();

0 commit comments

Comments
 (0)