Browse Source

feat: purge local repo action for git module

NGPixel 5 years ago
parent
commit
e68932aa40
2 changed files with 11 additions and 2 deletions
  1. 3 0
      server/modules/storage/git/definition.yml
  2. 8 2
      server/modules/storage/git/storage.js

+ 3 - 0
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.

+ 8 - 2
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()
   }
 }