ogit
Version:
A lazy developer's Git CLI made simple. Makes using git on cloud IDEs (i.e. C9) a walk in the park.
54 lines (53 loc) • 2.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const command_1 = require("@oclif/command");
const git_1 = require("../wrapper/git");
const OperationUtils_1 = require("../utils/OperationUtils");
const FileNameUtils_1 = require("../utils/FileNameUtils");
const inquirer = require("inquirer");
class RevertChanges extends command_1.Command {
run() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const status = yield git_1.GitFacade.status();
if (status.all.length === 0) {
console.log('You do not have any changes to revert');
}
else {
// const statusMap = new Map<string, GitFile>();
const revertList = [];
status.all.forEach(file => {
const changeType = FileNameUtils_1.FileNameUtils.getFileChangeType(file.changeType);
const key = `${file.path} ${changeType}`;
revertList.push({ name: key, value: file });
});
const verifyingNumber = OperationUtils_1.OperationUtils.getRandomVerificationNumber();
const answers = yield inquirer.prompt([
{
message: 'Select the file to revert changes' +
' (non-commited files will be deleted)',
type: 'checkbox',
choices: revertList,
name: 'revertList',
validate(choice) {
return choice.length > 0;
}
},
{
message: `Please enter ${verifyingNumber} on the prompt`,
type: 'input',
name: 'verificationConfirmed',
validate(number) {
return number === verifyingNumber;
}
}
]);
yield answers.revertList.forEach((file) => tslib_1.__awaiter(this, void 0, void 0, function* () {
yield git_1.GitFacade.revertFile(file);
}));
}
});
}
}
RevertChanges.description = 'Reverts an uncommitted change';
exports.default = RevertChanges;