ogit
Version:
A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.
82 lines (81 loc) • 3.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const AbstractBranchCommand_1 = require("../abstracts/AbstractBranchCommand");
const command_1 = require("@oclif/command");
const inquirer = require("inquirer");
const git_1 = require("../wrapper/git");
const OperationUtils_1 = require("../utils/OperationUtils");
const commit_changes_1 = require("./commit-changes");
class PullRemoteChangesCommand extends AbstractBranchCommand_1.default {
run() {
const _super = name => super[name];
return tslib_1.__awaiter(this, void 0, void 0, function* () {
let mergeCancelled = false;
const mergeConflictFiles = yield git_1.GitFacade.filesWithMergeConflicts();
if (mergeConflictFiles.length > 0) {
mergeCancelled = yield OperationUtils_1.OperationUtils.handleMergeConflicts(mergeConflictFiles);
}
if (!mergeCancelled) {
yield commit_changes_1.CommitChangesCommand.run(['--noSummary']);
const { flags } = this.parse(PullRemoteChangesCommand);
if (flags.trackingOnly) {
yield git_1.GitFacade.pullRemoteChanges();
}
else {
yield _super("runHelper").call(this);
}
}
});
}
getSelectedBranch() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { flags } = this.parse(PullRemoteChangesCommand);
const answers = yield inquirer.prompt([
{
message: flags.search
? 'Name of the remote branch to pull changes from'
: 'Select the remote branch to pull changes from',
type: flags.search ? 'autocomplete' : 'list',
choices: this.remoteBranches,
source: this.searchRemoteBranches,
name: 'remoteBranchName',
validate(choices) {
return choices.length > 0;
}
}
]);
return {
branchNameA: answers.remoteBranchName,
branchNameB: undefined
};
});
}
preformBranchOperation(branchInfo) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const remoteBranchName = branchInfo.branchNameA;
try {
yield git_1.GitFacade.pullRemoteChanges(remoteBranchName.substring(remoteBranchName.indexOf('/') + 1));
}
catch (error) {
console.log(error);
const conflictedFiles = yield git_1.GitFacade.filesWithMergeConflicts();
if (conflictedFiles) {
// console.log('Please resolve merge conflicts in the following files:');
// conflictedFiles.forEach(file => {
// console.log(file);
// });
yield OperationUtils_1.OperationUtils.handleMergeConflicts(conflictedFiles);
}
}
});
}
}
PullRemoteChangesCommand.description = 'Pull remote changes from a branch and merge';
PullRemoteChangesCommand.flags = {
// can pass either --trackingOnly or -t
trackingOnly: command_1.flags.boolean({ char: 't' }),
// can search --search or -s
search: command_1.flags.boolean({ char: 's' })
};
exports.PullRemoteChangesCommand = PullRemoteChangesCommand;