Merge pull request #2107 from harrellbm/develop

Hardened Git commands for branch switching
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2021-10-11 16:46:10 -04:00
commit 7ff1073be8
2 files changed
+35 -13

No files matched your search

+32 -12
View File
@@ -898,6 +898,27 @@ exports.newHttpInterface = function newHttpInterface() {
const git = simpleGit(options)
try {
await git.checkout(currentBranch)
// Check to see it main repo has been set as upstream
let remotes = await git.getRemotes();
let isUpstreamSet
for(let remote in remotes) {
if (remotes[remote].name === 'upstream') {
isUpstreamSet = true
} else {
isUpstreamSet = false
}
}
// If upstream has not been set. Set it now
if (isUpstreamSet === false){
await git.addRemote('upstream', 'https://github.com/Superalgos/Superalgos');
}
// Pull branch from main repo
await git.pull('upstream', currentBranch);
// Reset branch to match main repo
let upstreamLocation = `upstream/${currentBranch}`
await git.reset('hard', [upstreamLocation])
} catch (err) {
console.log('[ERROR] Error changing current branch to ' + currentBranch)
console.log(err.stack)
@@ -905,20 +926,19 @@ exports.newHttpInterface = function newHttpInterface() {
}
}
async function runNodeSetup() {
console.log("Running Node setup to adjust for new Branch")
const process = require("process");
const { execSync } = require("child_process");
async function runNodeSetup () {
console.log( "Running Node setup to adjust for new Branch" )
const process = SA.nodeModules.process
const childProcess = SA.nodeModules.childProcess
let dir = process.cwd()
let command = "node setup";
let stdout = execSync(command,
{
cwd: dir
}).toString();
console.log("Node Setup has completed with the following result:", stdout)
let command = "node setup noShortcuts";
let stdout = childProcess.execSync( command,
{
cwd: dir
}).toString();
console.log("Node Setup has completed with the following result:", stdout)
}
} catch (err) {
+3 -1
View File
@@ -48,7 +48,9 @@ SA.nodeModules = {
ccxt: require('ccxt'),
octokit: require("@octokit/rest"),
simpleGit: require('simple-git'),
lookpath: require('lookpath')
lookpath: require('lookpath'),
process: require('process'),
childProcess: require('child_process')
}
run()