예제 #1
0
def get_repo(path=None, alias=None, create=False):
    """
    Returns ``Repository`` object of type linked with given ``alias`` at
    the specified ``path``. If ``alias`` is not given it will try to guess it
    using get_scm method
    """
    if create:
        if not (path or alias):
            raise TypeError(
                "If create is specified, we need path and scm type")
        return get_backend(alias)(path, create=True)
    if path is None:
        path = abspath(os.path.curdir)
    try:
        scm, path = get_scm(path, search_recursively=True)
        path = abspath(path)
        alias = scm
    except VCSError:
        raise VCSError("No scm found at %s" % path)
    if alias is None:
        alias = get_scm(path)[0]

    backend = get_backend(alias)
    repo = backend(path, create=create)
    return repo
예제 #2
0
    def __init__(self, repo_path, create=False, src_url=None,
                 update_after_clone=False, bare=False):

        self.path = abspath(repo_path)
        self._repo = self._get_repo(create, src_url, update_after_clone, bare)
        #temporary set that to now at later we will move it to constructor
        baseui = None
        if baseui is None:
            from mercurial.ui import ui
            baseui = ui()
        # patch the instance of GitRepo with an "FAKE" ui object to add
        # compatibility layer with Mercurial
        setattr(self._repo, 'ui', baseui)

        try:
            self.head = self._repo.head()
        except KeyError:
            self.head = None

        self._config_files = [
            bare and abspath(self.path, 'config') or abspath(self.path, '.git',
                'config'),
            abspath(get_user_home(), '.gitconfig'),
        ]
        self.bare = self._repo.bare
예제 #3
0
    def __init__(self,
                 repo_path,
                 create=False,
                 src_url=None,
                 update_after_clone=False,
                 bare=False):

        self.path = abspath(repo_path)
        self._repo = self._get_repo(create, src_url, update_after_clone, bare)
        #temporary set that to now at later we will move it to constructor
        baseui = None
        if baseui is None:
            from mercurial.ui import ui
            baseui = ui()
        # patch the instance of GitRepo with an "FAKE" ui object to add
        # compatibility layer with Mercurial
        setattr(self._repo, 'ui', baseui)

        try:
            self.head = self._repo.head()
        except KeyError:
            self.head = None

        self._config_files = [
            bare and abspath(self.path, 'config')
            or abspath(self.path, '.git', 'config'),
            abspath(get_user_home(), '.gitconfig'),
        ]
예제 #4
0
    def __init__(self, repo_path, create=False, src_url=None, update_after_clone=False, bare=False):

        self.path = abspath(repo_path)
        repo = self._get_repo(create, src_url, update_after_clone, bare)
        self.bare = repo.bare

        self._config_files = [
            bare and abspath(self.path, "config") or abspath(self.path, ".git", "config"),
            abspath(get_user_home(), ".gitconfig"),
        ]
예제 #5
0
    def __init__(self, repo_path, create=False, src_url=None,
                 update_after_clone=False, bare=False):

        self.path = abspath(repo_path)
        repo = self._get_repo(create, src_url, update_after_clone, bare)
        self.bare = repo.bare

        self._config_files = [
            bare and abspath(self.path, 'config')
                     or abspath(self.path, '.git', 'config'),
            abspath(get_user_home(), '.gitconfig'),
        ]
예제 #6
0
    def __init__(self,
                 repo_path,
                 create=False,
                 baseui=None,
                 src_url=None,
                 update_after_clone=False):
        """
        Raises RepositoryError if repository could not be find at the given
        ``repo_path``.

        :param repo_path: local path of the repository
        :param create=False: if set to True, would try to create repository if
           it does not exist rather than raising exception
        :param baseui=None: user data
        :param src_url=None: would try to clone repository from given location
        :param update_after_clone=False: sets update of working copy after
          making a clone
        """

        if not isinstance(repo_path, str):
            raise VCSError('Mercurial backend requires repository path to '
                           'be instance of <str> got %s instead' %
                           type(repo_path))

        self.path = abspath(repo_path)
        self.baseui = baseui or ui.ui()
        # We've set path and ui, now we can set _repo itself
        self._repo = self._get_repo(create, src_url, update_after_clone)
예제 #7
0
def get_repo(path=None, alias=None, create=False):
    """
    Returns ``Repository`` object of type linked with given ``alias`` at
    the specified ``path``. If ``alias`` is not given it will try to guess it
    using get_scm method
    """
    if create:
        if not (path or alias):
            raise TypeError("If create is specified, we need path and scm type")
        return get_backend(alias)(path, create=True)
    if path is None:
        path = abspath(os.path.curdir)
    try:
        scm, path = get_scm(path, search_up=True)
        path = abspath(path)
        alias = scm
    except VCSError:
        raise VCSError("No scm found at %s" % path)
    if alias is None:
        alias = get_scm(path)[0]

    backend = get_backend(alias)
    repo = backend(path, create=create)
    return repo
예제 #8
0
def get_scm(path, search_recursively=False, explicit_alias=None):
    """
    Returns one of alias from ``ALIASES`` (in order of precedence same as
    shortcuts given in ``ALIASES``) and top working dir path for the given
    argument. If no scm-specific directory is found or more than one scm is
    found at that directory, ``VCSError`` is raised.

    :param search_recursively: if set to ``True``, this function would try to
      move up to parent directory every time no scm is recognized for the
      currently checked path. Default: ``False``.
    :param explicit_alias: can be one of available backend aliases, when given
      it will return given explicit alias in repositories under more than one
      version control, if explicit_alias is different than found it will raise
      VCSError
    """
    if not os.path.isdir(path):
        raise VCSError("Given path %s is not a directory" % path)

    def get_scms(path):
        return [(scm, path) for scm in get_scms_for_path(path)]

    found_scms = get_scms(path)
    while  not found_scms and search_recursively:
        newpath = abspath(path, '..')
        if newpath == path:
            break
        path = newpath
        found_scms = get_scms(path)

    if len(found_scms) > 1:
        for scm in found_scms:
            if scm[0] == explicit_alias:
                return scm
        raise VCSError('More than one [%s] scm found at given path %s'
                       % (','.join((x[0] for x in found_scms)), path))

    if len(found_scms) is 0:
        raise VCSError('No scm found at given path %s' % path)

    return found_scms[0]
예제 #9
0
    def __init__(self, repo_path, create=False, baseui=None, src_url=None, update_after_clone=False):
        """
        Raises RepositoryError if repository could not be find at the given
        ``repo_path``.

        :param repo_path: local path of the repository
        :param create=False: if set to True, would try to create repository if
           it does not exist rather than raising exception
        :param baseui=None: user data
        :param src_url=None: would try to clone repository from given location
        :param update_after_clone=False: sets update of working copy after
          making a clone
        """

        if not isinstance(repo_path, str):
            raise VCSError(
                "Mercurial backend requires repository path to " "be instance of <str> got %s instead" % type(repo_path)
            )

        self.path = abspath(repo_path)
        self.baseui = baseui or ui.ui()
        # We've set path and ui, now we can set _repo itself
        self._repo = self._get_repo(create, src_url, update_after_clone)
예제 #10
0
 def _config_files(self):
     return [
         self.bare and abspath(self.path, 'config')
                   or abspath(self.path, '.git', 'config'),
          abspath(get_user_home(), '.gitconfig'),
      ]
예제 #11
0
    def __init__(self, repo_path, create=False, src_url=None,
                 update_after_clone=False, bare=False):

        self.path = abspath(repo_path)
        repo = self._get_repo(create, src_url, update_after_clone, bare)
        self.bare = repo.bare
예제 #12
0
 def _config_files(self):
     return [
         self.bare and abspath(self.path, 'config')
                   or abspath(self.path, '.git', 'config'),
          abspath(get_user_home(), '.gitconfig'),
      ]
예제 #13
0
    def __init__(self, repo_path, create=False, src_url=None,
                 update_after_clone=False, bare=False):

        self.path = abspath(repo_path)
        repo = self._get_repo(create, src_url, update_after_clone, bare)
        self.bare = repo.bare