Skip to content

Commit

Permalink
https://github.com/haxtheweb/issues/issues/2162
Browse files Browse the repository at this point in the history
  • Loading branch information
btopro committed Oct 7, 2024
1 parent e5b3cd2 commit 7820801
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
43 changes: 31 additions & 12 deletions src/lib/GitPlus.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
module.exports = GitPlus;
}
4 changes: 2 additions & 2 deletions src/routes/createSite.js
Original file line number Diff line number Diff line change
@@ -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');

/**
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/gitImportSite.js
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/routes/publishSite.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/routes/syncSite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { HAXCMS } = require('../lib/HAXCMS.js');
const { Git } = require('git-interface');
const GitPlus = require('../lib/GitPlus.js');

/**
* @OA\Post(
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7820801

Please sign in to comment.