ogit
Version:
A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.
125 lines (124 loc) • 4.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const models_1 = require("../models");
const git_1 = require("../wrapper/git");
const inquirer = require("inquirer");
const chalk = require('chalk');
/* tslint:disable:no-unnecessary-class */
class OperationUtils {
}
OperationUtils.addNewFilesToRepo = (files) => {
files.forEach((file) => tslib_1.__awaiter(this, void 0, void 0, function* () {
if (file.changeType === models_1.ChangeTypes.New) {
yield git_1.GitFacade.addToRepo(file.path);
}
}));
};
OperationUtils.handleMergeConflicts = (files) => tslib_1.__awaiter(this, void 0, void 0, function* () {
// console.log(files);
let mergeCancelled = false;
console.log('The following files have merge conflicts that needs to be resolved before proceeding:');
for (const file of files) {
console.log(chalk.green(file));
}
const howToProceedPrompt = yield inquirer.prompt([
{
message: 'How would you like to resolve them?',
type: 'expand',
choices: [
{
key: 'C',
name: 'Cancel merge',
value: 'C'
},
{
key: 'M',
name: 'Accept all my changes',
value: 'M'
},
{
key: 'R',
name: 'Accept all remote changes',
value: 'R'
},
{
key: 'O',
name: 'Merge one by one',
value: 'O'
}
],
name: 'mergeOperation'
}
]);
// console.log(howToProceedPrompt);
if (howToProceedPrompt.mergeOperation === 'C') {
mergeCancelled = true;
yield git_1.GitFacade.cancelMerge();
}
else if (howToProceedPrompt.mergeOperation === 'M') {
yield git_1.GitFacade.acceptChanges(false);
}
else if (howToProceedPrompt.mergeOperation === 'R') {
yield git_1.GitFacade.acceptChanges(true);
}
else {
for (const file of files) {
const howToMergePrompt = yield inquirer.prompt([
{
message: `How would you like to resolve ${chalk.green(file)}?`,
type: 'expand',
choices: [
{
key: 'D',
name: 'Mark as merged',
value: 'D'
},
{
key: 'M',
name: 'Accept my changes',
value: 'M'
},
{
key: 'R',
name: 'Accept remote changes',
value: 'R'
},
{
key: 'C',
name: 'Later',
value: 'C'
}
],
name: 'mergeOperation'
}
]);
console.log(howToMergePrompt);
if (howToMergePrompt.mergeOperation === 'C') {
mergeCancelled = true;
}
else if (howToMergePrompt.mergeOperation === 'D') {
yield git_1.GitFacade.addToRepo(file);
}
else if (howToMergePrompt.mergeOperation === 'M') {
yield git_1.GitFacade.acceptChanges(false, file);
yield git_1.GitFacade.addToRepo(file);
}
else {
yield git_1.GitFacade.acceptChanges(true, file);
yield git_1.GitFacade.addToRepo(file);
}
}
if (!mergeCancelled) {
yield files.forEach((file) => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield git_1.GitFacade.addToRepo(file);
}));
yield git_1.GitFacade.commit('Manual merge done', files, false);
}
}
return mergeCancelled;
});
OperationUtils.getRandomVerificationNumber = () => {
return ('' + Math.random()).substr(4, 4);
};
exports.OperationUtils = OperationUtils;