UNPKG

@veecode-platform/safira-cli

Version:

Generate a microservice project from your spec.

46 lines (45 loc) 2.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GitCommand = void 0; const file_system_utils_1 = require("../utils/file-system-utils"); const git_exception_1 = require("../exception/git-exception"); const command_execute_1 = require("../command/command-execute"); class GitCommand { constructor() { } async pull(repoPath) { if (repoPath) { const fullRepoPath = file_system_utils_1.FileSystemUtils.fullPath(repoPath); if (!file_system_utils_1.FileSystemUtils.exists(file_system_utils_1.FileSystemUtils.buildPath(fullRepoPath, ".git"))) { throw new git_exception_1.NotGitRepositoryException(`${fullRepoPath} is not a git repository`); } await command_execute_1.CommandExecute.instance.exec(`${this.getClient()} -C ${fullRepoPath} pull`, false) .catch(error => { throw new git_exception_1.GitPullNotAllowedException(`Pull not allowed, check your repository ${fullRepoPath}`); }); } } async getCurrentBranch(repoPath) { return command_execute_1.CommandExecute.instance.exec(`${this.getClient()} rev-parse --abbrev-ref HEAD`, false) .then(value => value?.trim()); } async getRemoteOriginUrl(repoPath) { return command_execute_1.CommandExecute.instance.exec(`${this.getClient()} ${repoPath ? `-C ${file_system_utils_1.FileSystemUtils.fullPath(repoPath)}` : ""} config --get remote.origin.url`, false); } async lsRemote(gitRepository) { return command_execute_1.CommandExecute.instance.exec(`${this.getClient()} ls-remote ${gitRepository} -q`, false) .then(value => value.trim().length === 0); } getClient() { if (!file_system_utils_1.FileSystemUtils.commandExists("git")) { throw new git_exception_1.GitNotFoundException("Git not found, please install git"); } return "git"; } static get instance() { if (!this._instance) { this._instance = new this(); } return this._instance; } } exports.GitCommand = GitCommand;