ogit
Version:
A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.
73 lines (72 loc) • 2.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const AbstractBranchCommand_1 = require("../abstracts/AbstractBranchCommand");
const git_1 = require("../wrapper/git");
const command_1 = require("@oclif/command");
const inquirer = require("inquirer");
class CreateBranchCommand 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 localBranches = this.localBranches;
let remoteBranchName;
const { flags } = this.parse(CreateBranchCommand);
const answers = yield inquirer
.prompt([
{
message: flags.search
? 'Name of the remote branch to create local from'
: 'Select the remote branch to create local from',
type: flags.search ? 'autocomplete' : 'list',
source: this.searchRemoteBranches,
choices: this.remoteBranches,
name: 'remoteBranchName',
validate(choices) {
return choices.length > 0;
}
}
])
.then((answers) => {
return inquirer.prompt({
message: 'Local branch name',
type: 'input',
name: 'localBranchName',
default: () => {
remoteBranchName = answers.remoteBranchName;
return remoteBranchName.substring(remoteBranchName.indexOf('/') + 1);
},
validate(branchName) {
if (branchName) {
if (localBranches.indexOf(branchName) > -1) {
return `A local branch named ${branchName} already exists`;
}
return true;
}
return false;
}
});
});
return {
branchNameA: answers.localBranchName,
branchNameB: remoteBranchName
};
});
}
preformBranchOperation(branchInfo) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
yield git_1.GitFacade.createBranch(branchInfo.branchNameA, branchInfo.branchNameB);
});
}
}
CreateBranchCommand.description = 'Creates a new local branch from a remote branch';
CreateBranchCommand.flags = {
// can search --search or -s
search: command_1.flags.boolean({ char: 's' })
};
exports.CreateBranchCommand = CreateBranchCommand;