Ejemplo n.º 1
0
    def __init__(self, path=None):
        """
        Create a new Repo instance

        ``path``
            is the path to either the root git directory or the bare git repo

        Examples::

            repo = Repo("/Users/mtrier/Development/git-python")
            repo = Repo("/Users/mtrier/Development/git-python.git")

        Raises
            InvalidGitRepositoryError or NoSuchPathError

        Returns
            ``git.Repo``
        """

        epath = os.path.abspath(os.path.expanduser(path or os.getcwd()))

        if not os.path.exists(epath):
            raise NoSuchPathError(epath)

        self.path = None
        curpath = epath
        while curpath:
            if is_git_dir(curpath):
                self.bare = True
                self.path = curpath
                self.wd = curpath
                break
            gitpath = os.path.join(curpath, '.git')
            if is_git_dir(gitpath):
                self.bare = False
                self.path = gitpath
                self.wd = curpath
                break
            curpath, dummy = os.path.split(curpath)
            if not dummy:
                break

        if self.path is None:
           raise InvalidGitRepositoryError(epath)

        self.git = Git(self.wd)
        if not self.bare:
            self.git.extra["env"] = {
                "GIT_WORK_TREE": self.wd,
            }
Ejemplo n.º 2
0
    def __init__(self, path=None):
        """
        Create a new Repo instance

        ``path``
            is the path to either the root git directory or the bare git repo

        Examples::

            repo = Repo("/Users/mtrier/Development/git-python")
            repo = Repo("/Users/mtrier/Development/git-python.git")

        Raises
            InvalidGitRepositoryError or NoSuchPathError

        Returns
            ``git.Repo``
        """

        epath = os.path.abspath(os.path.expanduser(path or os.getcwd()))

        if not os.path.exists(epath):
            raise NoSuchPathError(epath)

        self.path = None
        curpath = epath
        while curpath:
            if is_git_dir(curpath):
                self.bare = True
                self.path = curpath
                self.wd = curpath
                break
            gitpath = os.path.join(curpath, '.git')
            if is_git_dir(gitpath):
                self.bare = False
                self.path = gitpath
                self.wd = curpath
                break
            curpath, dummy = os.path.split(curpath)
            if not dummy:
                break

        if self.path is None:
            raise InvalidGitRepositoryError(epath)

        self.git = Git(self.wd)
Ejemplo n.º 3
0
 def __init__(self,
              git_dir=None,
              glob=GBIN_FILE_GLOB,
              exclude_extensions=GBIN_EXCLUDE_EXT,
              excluded_fn=GBIN_EXCLUED_FN,
              inenv_manager=None):
     if not has_git_cmd():
         raise GbinException("No git command found.")
     git_dir = git_dir or self.closes_git_dir()
     if not is_git_dir(git_dir):
         raise GbinException("{} is not a git directory".format(git_dir))
     self._glob = glob
     self._ext_ex = exclude_extensions
     self._fn_ex = excluded_fn
     self.git_dir = git_dir
     self.inenv_manager = inenv_manager
Ejemplo n.º 4
0
 def _check_valid_path(self):
     assert os.path.isdir(self.path)
     assert is_git_dir(self.path), "not a Git dir?"