UNPKG

mlgc

Version:

MLGC is a CLI program that allows you to easily copy all Git changes to a folder for easy uploading or sharing.

40 lines (35 loc) 1.25 kB
const path = require("path"); const settings = require( path.join(__dirname, "..", "..", "config", "settings") ); const { execSync } = require("child_process"); function getIgnoredFiles() { return settings["ignored-files"] .map((file) => `| grep -v '^${file}'`) .join(" "); } function gitCommand(branchOrCommit) { const baseCommand = "git add -N . && git diff --name-only --diff-filter=d"; return branchOrCommit === "branch" ? `${baseCommand} origin/${getMainBranch()} ${getIgnoredFiles()}` : `${baseCommand} ${getIgnoredFiles()}`; } function getMainBranch() { try { // Führe den Git-Befehl aus const output = execSync("git symbolic-ref refs/remotes/origin/HEAD", { encoding: "utf-8", }); // Prüfe ob output existiert und nicht leer ist if (!output || typeof output !== "string") { throw new Error("Empty or invalid output"); } // Extrahiere den Branch-Namen aus dem Pfad return output.trim().split("/").pop(); } catch (error) { console.error("Error detecting main branch:", error.message); // Fallback auf "master", falls der Befehl fehlschlägt return "master"; } } module.exports = { gitCommand, getMainBranch };