"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const command_1 = require("@oclif/command");
const base_1 = tslib_1.__importDefault(require("../base"));
const logger_1 = tslib_1.__importDefault(require("../utils/logger"));
const git_1 = require("../utils/git");
const collection_1 = require("../utils/collection");
const constants_1 = require("../constants");
class Push extends base_1.default {
    async run() {
        const { flags } = this.parse(Push);
        this.userConfig = Object.assign(this.userConfig, flags);
        await collection_1.initializeTutureBranch();
        const remotes = await git_1.git.getRemotes(false);
        // Checkout tuture branch and add tuture.yml.
        await git_1.git.checkout(constants_1.TUTURE_BRANCH);
        if (!fs_extra_1.default.existsSync(constants_1.COLLECTION_PATH)) {
            logger_1.default.log('error', `Cannot push empty tuture branch. Please commit your tutorial with ${chalk_1.default.bold('tuture commit')}.`);
            this.exit(1);
        }
        await git_1.git.push(remotes[0].name, constants_1.TUTURE_BRANCH);
        // Commit changes to tuture branch.
        logger_1.default.log('success', 'Pushed to remote.');
    }
}
exports.default = Push;
Push.description = 'Push the tuture branch to remote';
Push.flags = {
    help: command_1.flags.help({ char: 'h' }),
};
