"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _child_process = require("child_process");

var _utils = require("../utils");

var _log = require("./log");

var _default = (type = 'git', branchName) => new Promise(resolve => {
  if (type === 'git') {
    (0, _log.log)((0, _utils.getCurrentBranch)(type, process.cwd()), 'Before the branch switch');
    (0, _child_process.spawnSync)('git', ['checkout', branchName, '--force'], {
      encoding: 'utf8'
    });
    (0, _log.log)((0, _utils.getCurrentBranch)(type, process.cwd()), 'After the branch switch');
    (0, _utils.pullOrigin)(type, branchName).then(resolve);
  } else if (type === 'hg') {
    (0, _child_process.spawnSync)('hg', ['update', branchName], {
      encoding: 'utf8'
    });
    (0, _utils.pullOrigin)(type, branchName).then(resolve);
  }
});

exports.default = _default;