How to use the tsrc.git.Error function in tsrc

To help you get started, we’ve selected a few tsrc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TankerHQ / tsrc / tsrc / git.py View on Github external
def find_ref(repo: Path, candidate_refs: Iterable[str]) -> str:
    """ Find the first reference that exists in the given repo """
    run(repo, "fetch", "--all", "--prune")
    for candidate_ref in candidate_refs:
        code, _ = run_captured(repo, "rev-parse", candidate_ref, check=False)
        if code == 0:
            return candidate_ref
    ref_list = ", ".join(candidate_refs)
    raise Error("Could not find any of:", ref_list, "in repo", repo)
github TankerHQ / tsrc / tsrc / git.py View on Github external
def update_branch(self) -> None:
        try:
            self.branch = get_current_branch(self.working_path)
        except Error:
            pass
github TankerHQ / tsrc / tsrc / git.py View on Github external
self.cmd = cmd
        self.working_path = working_path
        self.output = output
        message = "`git {cmd}` from {working_path} failed"
        message = message.format(cmd=" ".join(cmd), working_path=working_path)
        if output:
            message += "\n" + output
        super().__init__(message)


class NoSuchWorkingPath(Error):
    def __init__(self, path: Path) -> None:
        super().__init__("'{}' does not exist".format(path))


class WorktreeNotFound(Error):
    def __init__(self, working_path: Path) -> None:
        super().__init__("'{}' is not inside a git repository".format(working_path))


def assert_working_path(path: Path) -> None:
    if not path.exists():
        raise NoSuchWorkingPath(path)


class Status:
    def __init__(self, working_path: Path) -> None:
        self.working_path = working_path
        self.untracked = 0
        self.staged = 0
        self.not_staged = 0
        self.added = 0
github TankerHQ / tsrc / tsrc / git.py View on Github external
import os
import subprocess
from typing import Any, Dict, Iterable, Tuple, Optional  # noqa

from path import Path
import cli_ui as ui

import tsrc


class Error(tsrc.Error):
    pass


class CommandError(Error):
    def __init__(
        self, working_path: Path, cmd: Iterable[str], *, output: Optional[str] = None
    ) -> None:
        self.cmd = cmd
        self.working_path = working_path
        self.output = output
        message = "`git {cmd}` from {working_path} failed"
        message = message.format(cmd=" ".join(cmd), working_path=working_path)
        if output:
            message += "\n" + output
        super().__init__(message)


class NoSuchWorkingPath(Error):
    def __init__(self, path: Path) -> None:
        super().__init__("'{}' does not exist".format(path))
github TankerHQ / tsrc / tsrc / git.py View on Github external
def get_current_branch(working_path: Path) -> str:
    cmd = ("rev-parse", "--abbrev-ref", "HEAD")
    _, output = run_captured(working_path, *cmd)
    if output == "HEAD":
        raise Error("Not an any branch")
    return output
github TankerHQ / tsrc / tsrc / git.py View on Github external
class CommandError(Error):
    def __init__(
        self, working_path: Path, cmd: Iterable[str], *, output: Optional[str] = None
    ) -> None:
        self.cmd = cmd
        self.working_path = working_path
        self.output = output
        message = "`git {cmd}` from {working_path} failed"
        message = message.format(cmd=" ".join(cmd), working_path=working_path)
        if output:
            message += "\n" + output
        super().__init__(message)


class NoSuchWorkingPath(Error):
    def __init__(self, path: Path) -> None:
        super().__init__("'{}' does not exist".format(path))


class WorktreeNotFound(Error):
    def __init__(self, working_path: Path) -> None:
        super().__init__("'{}' is not inside a git repository".format(working_path))


def assert_working_path(path: Path) -> None:
    if not path.exists():
        raise NoSuchWorkingPath(path)


class Status:
    def __init__(self, working_path: Path) -> None: