UNPKG

git-command-helper

Version:
42 lines (39 loc) 1.13 kB
// git-command-helper 2.1.0 by Dimas Lanjaka <dimaslanjaka@gmail.com> (https://www.webmanajemen.com) import { async } from 'cross-spawn'; /** * Performs a git dry-run for the specified commands to check if there are changes to push. * @param cwd - The working directory where the git command should be executed. * @param commands - The git command arguments (e.g., ["push", origin, branch]). */ async function dryRun({ cwd, commands }) { const dry = await async("git", [...commands, "--dry-run"], { stdio: "pipe", cwd }); return dry.output.trim() != "Everything up-to-date"; } /** * Checks if the current branch can be pushed to the specified origin and branch. * @param cwd - The working directory where the git command should be executed. * @param origin - The name of the remote origin. * @param branch - The name of the branch to push. */ async function isCanPush({ cwd, origin, branch }) { try { const can = await dryRun({ cwd, commands: ["push", origin, branch] }); return can ? true : false; } catch { return false; } } export { dryRun, isCanPush };