From 78208010f09f1810ea10af4e1abfa0806aa5c4bd Mon Sep 17 00:00:00 2001 From: btopro Date: Mon, 7 Oct 2024 14:25:42 -0400 Subject: [PATCH] https://github.com/haxtheweb/issues/issues/2162 --- src/lib/GitPlus.js | 43 ++++++++++++++++++++++++++----------- src/routes/createSite.js | 4 ++-- src/routes/gitImportSite.js | 4 ++-- src/routes/publishSite.js | 4 ++-- src/routes/syncSite.js | 4 ++-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/lib/GitPlus.js b/src/lib/GitPlus.js index b5acbf7..401110a 100644 --- a/src/lib/GitPlus.js +++ b/src/lib/GitPlus.js @@ -1,18 +1,37 @@ const { Git } = require('git-interface'); +const util = require('node:util'); +const child_process = require('child_process'); +const exec = util.promisify(child_process.exec); +var hasGit = true; +exec('git --version', error => { + if (error) { + hasGit = false; + } +}); +console.log(hasGit); -class GitPlus extends Git { - async revert(count) { - let counter = 0; - // sanity check - if (count < 1) { - count = 1; - } - while (counter != count) { - await this.gitExec("reset --hard HEAD~1"); - counter++; +if (hasGit) { + class GitPlus extends Git { + async revert(count) { + let counter = 0; + // sanity check + if (count < 1) { + count = 1; + } + while (counter != count) { + await this.gitExec("reset --hard HEAD~1"); + counter++; + } + return true; } - return true; } + module.exports = GitPlus; } +else { + class GitPlus { + constructor() { -module.exports = GitPlus; \ No newline at end of file + } + } + module.exports = GitPlus; +} \ No newline at end of file diff --git a/src/routes/createSite.js b/src/routes/createSite.js index e6ee0b3..4aea658 100644 --- a/src/routes/createSite.js +++ b/src/routes/createSite.js @@ -1,5 +1,5 @@ const { HAXCMS } = require('../lib/HAXCMS.js'); -const { Git } = require('git-interface'); +const GitPlus = require('../lib/GitPlus.js'); const JSONOutlineSchemaItem = require('../lib/JSONOutlineSchemaItem.js'); /** @@ -185,7 +185,7 @@ async function createSite(req, res) { delete schema.metadata.site.git; try { - const git = new Git({ + const git = new GitPlus({ dir: site.siteDirectory }); git.setDir(site.siteDirectory); diff --git a/src/routes/gitImportSite.js b/src/routes/gitImportSite.js index ef556f5..ef7ad60 100644 --- a/src/routes/gitImportSite.js +++ b/src/routes/gitImportSite.js @@ -1,7 +1,7 @@ const { HAXCMS } = require('../lib/HAXCMS.js'); const explode = require('locutus/php/strings/explode'); const filter_var = require('../lib/filter_var.js'); -const { Git } = require('git-interface'); +const GitPlus = require('../lib/GitPlus.js'); /** * @OA\Post( * path="/gitImportSite", @@ -51,7 +51,7 @@ const { Git } = require('git-interface'); // @todo check if this fails directory = HAXCMS.HAXCMS_ROOT + HAXCMS.sitesDirectory + '/' + repo_path; try { - let git = new Git(); + let git = new GitPlus(); let repo = git.create(directory); repo = git.open(directory, true); repo.set_remote("origin", repoUrl); diff --git a/src/routes/publishSite.js b/src/routes/publishSite.js index 799fc60..0e30b95 100644 --- a/src/routes/publishSite.js +++ b/src/routes/publishSite.js @@ -3,7 +3,7 @@ const { HAXCMS } = require('../lib/HAXCMS.js'); const explode = require('locutus/php/strings/explode'); const parse_url = require('locutus/php/url/parse_url'); const strtr = require('locutus/php/strings/strtr'); -const { Git } = require('git-interface'); +const GitPlus = require('../lib/GitPlus.js'); /** * @OA\Post( @@ -57,7 +57,7 @@ const { Git } = require('git-interface'); } if ((gitSettings)) { try { - let git = new Git(); + let git = new GitPlus(); let repo = git.open(site.siteDirectory, true); // ensure we're on master and everything is added await repo.checkout('master'); diff --git a/src/routes/syncSite.js b/src/routes/syncSite.js index 96ddd76..d9c3f48 100644 --- a/src/routes/syncSite.js +++ b/src/routes/syncSite.js @@ -1,5 +1,5 @@ const { HAXCMS } = require('../lib/HAXCMS.js'); -const { Git } = require('git-interface'); +const GitPlus = require('../lib/GitPlus.js'); /** * @OA\Post( @@ -52,7 +52,7 @@ const { Git } = require('git-interface'); } if ((gitSettings)) { try { - let git = new Git(); + let git = new GitPlus(); let repo = git.open(site.siteDirectory, true); // ensure we're on branch, most likley master await repo.checkout(gitSettings.branch);