UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

92 lines (91 loc) 4.27 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); /** * Pull branch with losing changes */ const NewCommand = { alias: ['pf', 'pull-force'], description: 'Force pull (discard local)', hidden: false, name: 'force-pull', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { var _a, _b, _c; // Retrieve the tools we need const { config, git, helper, parameters, print: { info, spin, success, warning }, prompt, system: { run, startTimer }, } = toolbox; // Load configuration const ltConfig = config.loadConfig(); // Parse CLI arguments const dryRun = parameters.options.dryRun || parameters.options['dry-run']; // Determine noConfirm with priority: CLI > config > global > default (false) const noConfirm = config.getNoConfirm({ cliValue: parameters.options.noConfirm, commandConfig: (_b = (_a = ltConfig === null || ltConfig === void 0 ? void 0 : ltConfig.commands) === null || _a === void 0 ? void 0 : _a.git) === null || _b === void 0 ? void 0 : _b.forcePull, config: ltConfig, parentConfig: (_c = ltConfig === null || ltConfig === void 0 ? void 0 : ltConfig.commands) === null || _c === void 0 ? void 0 : _c.git, }); // Check git if (!(yield git.gitInstalled())) { return; } // Get current branch const branch = yield git.currentBranch(); // Dry-run mode: show what would be affected if (dryRun) { warning('DRY-RUN MODE - No changes will be made'); info(''); // Show local changes that would be lost const status = yield run('git status --porcelain'); if (status === null || status === void 0 ? void 0 : status.trim()) { const lines = status.trim().split('\n'); info(`Would discard on branch "${branch}":`); info(` - ${lines.length} file(s) with local changes`); info(''); info('Files:'); lines.forEach((line) => info(` ${line}`)); } else { info('No local changes to discard.'); } // Show commits that would be lost const localCommits = yield run(`git log origin/${branch}..HEAD --oneline 2>/dev/null || echo ""`); if (localCommits === null || localCommits === void 0 ? void 0 : localCommits.trim()) { info(''); info('Local commits that would be lost:'); localCommits .trim() .split('\n') .forEach((line) => info(` ${line}`)); } return `dry-run force-pull branch ${branch}`; } // Ask for reset if (!noConfirm && !(yield prompt.confirm('You will lose your changes, are you sure?'))) { return; } // Start timer const timer = startTimer(); // Reset soft const pullSpinner = spin(`Fetch and pull ${branch}`); yield run(`git fetch && git reset origin/${branch} --hard`); pullSpinner.succeed(); // Success success(`Force pulled ${branch} in ${helper.msToMinutesAndSeconds(timer())}m.`); info(''); // Exit if not running from menu if (!toolbox.parameters.options.fromGluegunMenu) { process.exit(); } // For tests return `force pulled ${branch}`; }), }; exports.default = NewCommand;