From b521d44f668d24d8a90131f3469493662f7b74c4 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Sat, 27 Jan 2024 15:38:40 +0100 Subject: [PATCH] added git_reset --- .../installs_steps_methods/git_reset.js | 30 +++++++++++++++++++ .../pkg_mng/installs_steps_methods/index.js | 8 +++++ 2 files changed, 38 insertions(+) create mode 100644 src/main/pkg_mng/installs_steps_methods/git_reset.js diff --git a/src/main/pkg_mng/installs_steps_methods/git_reset.js b/src/main/pkg_mng/installs_steps_methods/git_reset.js new file mode 100644 index 0000000..39d6b4c --- /dev/null +++ b/src/main/pkg_mng/installs_steps_methods/git_reset.js @@ -0,0 +1,30 @@ + +import path from "node:path" +import fs from "node:fs" +import ChildProcess from "node:child_process" + +import sendToRender from "../../utils/sendToRender" + +export default async (manifest, step) => { + const _path = path.resolve(manifest.install_path, step.path) + const from = step.from ?? "origin/main" + + sendToRender(`pkg:update:status`, { + id: manifest.id, + statusText: `Reset from ${from}`, + }) + + console.log(`[${manifest.id}] steps.git_reset() | Reseting to ${from}...`) + + fs.mkdirSync(_path, { recursive: true }) + + await new Promise((resolve, reject) => { + const process = ChildProcess.exec(`${global.GIT_PATH ?? "git"} reset --hard ${from}`, { + cwd: _path, + shell: true, + }) + + process.on("exit", resolve) + process.on("error", reject) + }) +} \ No newline at end of file diff --git a/src/main/pkg_mng/installs_steps_methods/index.js b/src/main/pkg_mng/installs_steps_methods/index.js index 5e349f9..77264bd 100644 --- a/src/main/pkg_mng/installs_steps_methods/index.js +++ b/src/main/pkg_mng/installs_steps_methods/index.js @@ -2,12 +2,14 @@ import ISM_DRIVE_DL from "./drive" import ISM_HTTP from "./http" import ISM_GIT_CLONE from "./git_clone" import ISM_GIT_PULL from "./git_pull" +import ISM_GIT_RESET from "./git_reset" const InstallationStepsMethods = { drive_dl: ISM_DRIVE_DL, http: ISM_HTTP, git_clone: ISM_GIT_CLONE, git_pull: ISM_GIT_PULL, + git_reset: ISM_GIT_RESET, } export default async function processGenericSteps(pkg, steps) { @@ -42,6 +44,12 @@ export default async function processGenericSteps(pkg, steps) { } break; } + case "git_reset": { + for await (const reset_step of stepValue) { + await InstallationStepsMethods.git_reset(pkg, reset_step) + } + break; + } default: { throw new Error(`Unknown step: ${stepKey}`) }