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.

76 lines (75 loc) 3.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const AbstractBranchCommand_1 = require("../abstracts/AbstractBranchCommand"); const inquirer = require("inquirer"); const command_1 = require("@oclif/command"); const OperationUtils_1 = require("../utils/OperationUtils"); const git_1 = require("../wrapper/git"); class MergeRemoteBranches extends AbstractBranchCommand_1.default { getSelectedBranch() { return tslib_1.__awaiter(this, void 0, void 0, function* () { let sourceBranch; const { flags } = this.parse(MergeRemoteBranches); const answers = yield inquirer .prompt({ message: flags.search ? 'Name of the source branch to merge' : 'Select the source branch to merge', type: flags.search ? 'autocomplete' : 'list', source: this.searchRemoteBranches, choices: this.remoteBranches, name: 'sourceBranch' }) .then(answers => { return inquirer.prompt({ message: flags.search ? 'Name of the target branch to merge into' : 'Select the target branch to merge into', source: this.searchRemoteBranches, type: flags.search ? 'autocomplete' : 'list', choices: () => { // console.log('validating'); sourceBranch = answers.sourceBranch; return this.remoteBranches.filter(item => item !== answers.sourceBranch); }, name: 'targetBranch', validate(choices) { return choices.length > 0; } }); }); return { branchNameA: sourceBranch, branchNameB: answers.targetBranch }; }); } preformBranchOperation(branchInfo) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const randomNumber = OperationUtils_1.OperationUtils.getRandomVerificationNumber(); const sourceBranchName = `${randomNumber}_${branchInfo.branchNameA}`; const targetBranchName = `${randomNumber}_${branchInfo.branchNameB}`; const currentBranchName = yield git_1.GitFacade.getCurrentBranchName(); yield git_1.GitFacade.createBranch(sourceBranchName, branchInfo.branchNameA); yield git_1.GitFacade.createBranch(targetBranchName, branchInfo.branchNameB); yield git_1.GitFacade.merge(sourceBranchName, `Merged branch ${branchInfo.branchNameA} into ${branchInfo.branchNameB}`); yield git_1.GitFacade.push([`HEAD:${branchInfo.branchNameB}`]); yield git_1.GitFacade.switchBranch(currentBranchName); yield git_1.GitFacade.deleteLocalBranch(sourceBranchName); yield git_1.GitFacade.deleteLocalBranch(targetBranchName); // console.log(sourceBranchName, targetBranchName); }); } run() { return tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.runHelper(); }); } } MergeRemoteBranches.description = 'Merges two remote branches'; MergeRemoteBranches.flags = { // can search --search or -s search: command_1.flags.boolean({ char: 's' }) }; exports.MergeRemoteBranches = MergeRemoteBranches;