From e68932aa407681bc46a0d431c63a1a3811edc30b Mon Sep 17 00:00:00 2001 From: NGPixel Date: Mon, 3 Feb 2020 23:39:00 -0500 Subject: [PATCH] feat: purge local repo action for git module --- server/modules/storage/git/definition.yml | 3 +++ server/modules/storage/git/storage.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/server/modules/storage/git/definition.yml b/server/modules/storage/git/definition.yml index 9e778eac..dcdeff65 100644 --- a/server/modules/storage/git/definition.yml +++ b/server/modules/storage/git/definition.yml @@ -109,3 +109,6 @@ actions: - handler: importAll label: Import Everything hint: Will import all content currently in the local Git repository, regardless of the latest commit state. Useful for importing content from the remote repository created before git was enabled. + - handler: purge + label: Purge Local Repository + hint: If you have unrelated merge histories, clearing the local repository can resolve this issue. This will not affect the remote repository or perform any commit. diff --git a/server/modules/storage/git/storage.js b/server/modules/storage/git/storage.js index f8b32112..0e2c1bee 100644 --- a/server/modules/storage/git/storage.js +++ b/server/modules/storage/git/storage.js @@ -78,8 +78,8 @@ module.exports = { } } if (this.config.sshPort <= 0) { - this.config.sshPort = 22 - } + this.config.sshPort = 22 + } await this.git.addConfig('core.sshCommand', `ssh -i "${this.config.sshPrivateKeyPath}" -o StrictHostKeyChecking=no -p ${this.config.sshPort}`) WIKI.logger.info('(STORAGE/GIT) Adding origin remote via SSH...') await this.git.addRemote('origin', this.config.repoUrl) @@ -443,5 +443,11 @@ module.exports = { await this.git.commit(`docs: add all untracked content`) WIKI.logger.info('(STORAGE/GIT) All content is now tracked.') + }, + async purge() { + WIKI.logger.info(`(STORAGE/GIT) Purging local repository...`) + await fs.emptyDir(this.repoPath) + WIKI.logger.info('(STORAGE/GIT) Local repository is now empty. Reinitializing...') + await this.init() } }