UNPKG

ogit

Version:

A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.

69 lines (68 loc) 2.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const AbstractBranchCommand_1 = require("../abstracts/AbstractBranchCommand"); const git_1 = require("../wrapper/git"); const inquirer = require("inquirer"); class DeleteBranchCommand extends AbstractBranchCommand_1.default { run() { const _super = name => super[name]; return tslib_1.__awaiter(this, void 0, void 0, function* () { yield _super("runHelper").call(this); }); } getSelectedBranch() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const branchNames = []; const verifyingNumber = ('' + Math.random()).substr(4, 4); this.branchesList.forEach(branch => { if (!branch.isCurrent) { branchNames.push({ name: `${this.getName(branch)} (${this.getType(branch)})`, value: branch }); } }); const answers = yield inquirer.prompt([ { message: 'Select the branch to delete', type: 'list', choices: branchNames, name: 'selectedBranch', validate(choices) { return choices.length > 0; } }, { message: `Please enter ${verifyingNumber} on the prompt`, type: 'input', name: 'localBranchName', validate(number) { return number === verifyingNumber; } } ]); const selectBranchName = answers.selectedBranch.name; return { branchNameA: this.localBranches.indexOf(selectBranchName) > -1 ? selectBranchName : undefined, branchNameB: this.remoteBranches.indexOf(selectBranchName) > -1 ? selectBranchName : undefined }; }); } preformBranchOperation(branchInfo) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (branchInfo.branchNameA) { yield git_1.GitFacade.deleteLocalBranch(branchInfo.branchNameA); } else { yield git_1.GitFacade.deleteRemoteBranch(branchInfo.branchNameB); } }); } } DeleteBranchCommand.description = 'Deletes a branch from the repo'; exports.DeleteBranchCommand = DeleteBranchCommand;