Example #1
0
    def repo_scan(self, repos_path=None):
        """
        Listing of repositories in given path. This path should not be a
        repository itself. Return a dictionary of repository objects

        :param repos_path: path to directory containing repositories
        """

        if repos_path is None:
            repos_path = self.repos_path

        log.info('scanning for repositories in %s', repos_path)

        config = make_db_config()
        config.set('extensions', 'largefiles', '')
        repos = {}

        for name, path in get_filesystem_repos(repos_path, recursive=True):
            # name need to be decomposed and put back together using the /
            # since this is internal storage separator for rhodecode
            name = Repository.normalize_repo_name(name)

            try:
                if name in repos:
                    raise RepositoryError('Duplicate repository name %s '
                                          'found in %s' % (name, path))
                elif path[0] in rhodecode.BACKENDS:
                    klass = get_backend(path[0])
                    repos[name] = klass(path[1], config=config)
            except OSError:
                continue
        log.debug('found %s paths with repositories', len(repos))
        return repos
Example #2
0
    def __get_instance(self):

        repo_full_path = self.repo_full_path

        try:
            alias = get_scm(repo_full_path)[0]
            log.debug("Creating instance of %s repository" % alias)
            backend = get_backend(alias)
        except VCSError:
            log.error(traceback.format_exc())
            log.error(
                "Perhaps this repository is in db and not in "
                "filesystem run rescan repositories with "
                '"destroy old data " option from admin panel'
            )
            return

        if alias == "hg":

            repo = backend(safe_str(repo_full_path), create=False, baseui=self._ui)
            # skip hidden web repository
            if repo._get_hidden():
                return
        else:
            repo = backend(repo_full_path, create=False)

        return repo
def test_get_repo_autoalias_hg():
    alias = 'hg'
    path = TEST_HG_REPO
    backend = get_backend(alias)
    repo = backend(path)

    assert repo.__class__ == get_repo(path).__class__
    assert repo.path == get_repo(path).path
def test_get_repo_autoalias_git():
    alias = 'git'
    path = TEST_GIT_REPO
    backend = get_backend(alias)
    repo = backend(path)

    assert repo.__class__ == get_repo(path).__class__
    assert repo.path == get_repo(path).path
Example #5
0
    def test_get_repo(self):
        alias = 'hg'
        path = TEST_HG_REPO
        backend = get_backend(alias)
        repo = backend(path)

        self.assertEqual(repo.__class__, get_repo(path, alias).__class__)
        self.assertEqual(repo.path, get_repo(path, alias).path)
def test_get_repo():
    alias = 'hg'
    path = TEST_HG_REPO
    backend = get_backend(alias)
    repo = backend(path)

    assert repo.__class__, get_repo(path == alias).__class__
    assert repo.path, get_repo(path == alias).path
Example #7
0
    def test_get_repo_autoalias_git(self):
        alias = 'git'
        path = TEST_GIT_REPO
        backend = get_backend(alias)
        repo = backend(path)

        self.assertEqual(repo.__class__, get_repo(path).__class__)
        self.assertEqual(repo.path, get_repo(path).path)
Example #8
0
    def repo_scan(self, repos_path=None):
        """
        Listing of repositories in given path. This path should not be a
        repository itself. Return a dictionary of repository objects

        :param repos_path: path to directory containing repositories
        """

        if repos_path is None:
            repos_path = self.repos_path

        log.info('scanning for repositories in %s' % repos_path)

        baseui = make_ui('db')
        repos = {}

        for name, path in get_filesystem_repos(repos_path, recursive=True):
            # skip removed repos
            if REMOVED_REPO_PAT.match(name):
                continue

            # name need to be decomposed and put back together using the /
            # since this is internal storage separator for rhodecode
            name = Repository.url_sep().join(name.split(os.sep))

            try:
                if name in repos:
                    raise RepositoryError('Duplicate repository name %s '
                                          'found in %s' % (name, path))
                else:

                    klass = get_backend(path[0])

                    if path[0] == 'hg' and path[0] in BACKENDS.keys():
                        repos[name] = klass(safe_str(path[1]), baseui=baseui)

                    if path[0] == 'git' and path[0] in BACKENDS.keys():
                        repos[name] = klass(path[1])
            except OSError:
                continue

        return repos
Example #9
0
    def repo_scan(self, repos_path=None):
        """
        Listing of repositories in given path. This path should not be a
        repository itself. Return a dictionary of repository objects

        :param repos_path: path to directory containing repositories
        """

        if repos_path is None:
            repos_path = self.repos_path

        log.info('scanning for repositories in %s' % repos_path)

        baseui = make_ui('db')
        repos = {}

        for name, path in get_filesystem_repos(repos_path, recursive=True):
            # skip removed repos
            if REMOVED_REPO_PAT.match(name):
                continue

            # name need to be decomposed and put back together using the /
            # since this is internal storage separator for rhodecode
            name = Repository.url_sep().join(name.split(os.sep))

            try:
                if name in repos:
                    raise RepositoryError('Duplicate repository name %s '
                                          'found in %s' % (name, path))
                else:

                    klass = get_backend(path[0])

                    if path[0] == 'hg' and path[0] in BACKENDS.keys():
                        repos[name] = klass(safe_str(path[1]), baseui=baseui)

                    if path[0] == 'git' and path[0] in BACKENDS.keys():
                        repos[name] = klass(path[1])
            except OSError:
                continue

        return repos
Example #10
0
    def __get_instance(self):
        repo_full_path = self.repo_full_path
        try:
            alias = get_scm(repo_full_path)[0]
            log.debug('Creating instance of %s repository' % alias)
            backend = get_backend(alias)
        except VCSError:
            log.error(traceback.format_exc())
            log.error('Perhaps this repository is in db and not in '
                      'filesystem run rescan repositories with '
                      '"destroy old data " option from admin panel')
            return

        if alias == 'hg':

            repo = backend(safe_str(repo_full_path), create=False,
                           config=self._config)
        else:
            repo = backend(repo_full_path, create=False)

        return repo
Example #11
0
def create_repo_fork(form_data, cur_user):
    """
    Creates a fork of repository using interval VCS methods

    :param form_data:
    :param cur_user:
    """
    from rhodecode.model.repo import RepoModel

    log = get_logger(create_repo_fork)
    DBS = get_session()

    base_path = Repository.base_path()

    fork_repo = RepoModel(DBS).create(form_data, cur_user,
                                      just_db=True, fork=True)

    alias = form_data['repo_type']
    org_repo_name = form_data['org_path']
    fork_name = form_data['repo_name_full']
    update_after_clone = form_data['update_after_clone']
    source_repo_path = os.path.join(base_path, org_repo_name)
    destination_fork_path = os.path.join(base_path, fork_name)

    log.info('creating fork of %s as %s', source_repo_path,
             destination_fork_path)
    backend = get_backend(alias)
    backend(safe_str(destination_fork_path), create=True,
            src_url=safe_str(source_repo_path),
            update_after_clone=update_after_clone)
    log_create_repository(fork_repo.get_dict(), created_by=cur_user.username)

    action_logger(cur_user, 'user_forked_repo:%s' % fork_name,
                   org_repo_name, '', DBS)

    action_logger(cur_user, 'user_created_fork:%s' % fork_name,
                   fork_name, '', DBS)
    # finally commit at latest possible stage
    DBS.commit()
Example #12
0
 def test_alias_detect_git(self):
     alias = 'git'
     path = TEST_GIT_REPO
     backend = get_backend(alias)
     repo = backend(path)
     self.assertEqual('git',repo.alias)
Example #13
0
 def get_backend(cls):
     return vcs.get_backend(cls.backend_alias)
Example #14
0
 def test_get_backend(self):
     hg = get_backend('hg')
     self.assertEqual(hg, MercurialRepository)
Example #15
0
 def test_alias_detect_hg(self):
     alias = 'hg'
     path = TEST_HG_REPO
     backend = get_backend(alias)
     repo = backend(path)
     self.assertEqual('hg',repo.alias)
Example #16
0
def create_repo_fork(form_data, cur_user):
    """
    Creates a fork of repository using interval VCS methods

    :param form_data:
    :param cur_user:
    """
    from rhodecode.model.repo import RepoModel
    from rhodecode.model.user import UserModel

    log = get_logger(create_repo_fork)
    DBS = get_session()

    base_path = Repository.base_path()
    cur_user = UserModel(DBS)._get_user(cur_user)

    fork_name = form_data["repo_name_full"]
    repo_type = form_data["repo_type"]
    description = form_data["description"]
    owner = cur_user
    private = form_data["private"]
    clone_uri = form_data.get("clone_uri")
    repos_group = form_data["repo_group"]
    landing_rev = form_data["landing_rev"]
    copy_fork_permissions = form_data.get("copy_permissions")
    fork_of = RepoModel(DBS)._get_repo(form_data.get("fork_parent_id"))

    fork_repo = RepoModel(DBS).create_repo(
        fork_name,
        repo_type,
        description,
        owner,
        private,
        clone_uri,
        repos_group,
        landing_rev,
        just_db=True,
        fork_of=fork_of,
        copy_fork_permissions=copy_fork_permissions,
    )

    update_after_clone = form_data["update_after_clone"]

    source_repo_path = os.path.join(base_path, fork_of.repo_name)
    destination_fork_path = os.path.join(base_path, fork_name)

    log.info("creating fork of %s as %s", source_repo_path, destination_fork_path)
    backend = get_backend(repo_type)

    if repo_type == "git":
        r = backend(
            safe_str(destination_fork_path),
            create=True,
            src_url=safe_str(source_repo_path),
            update_after_clone=update_after_clone,
            bare=True,
        )
        # add rhodecode hook into this repo
        ScmModel().install_git_hook(repo=r)
    elif repo_type == "hg":
        r = backend(
            safe_str(destination_fork_path),
            create=True,
            src_url=safe_str(source_repo_path),
            update_after_clone=update_after_clone,
        )
    else:
        raise Exception("Unknown backend type %s" % repo_type)

    log_create_repository(fork_repo.get_dict(), created_by=cur_user.username)

    action_logger(cur_user, "user_forked_repo:%s" % fork_name, fork_of.repo_name, "", DBS)

    action_logger(cur_user, "user_created_fork:%s" % fork_name, fork_name, "", DBS)
    # finally commit at latest possible stage
    DBS.commit()
    fork_repo.update_changeset_cache()
Example #17
0
def create_repo_fork(form_data, cur_user):
    """
    Creates a fork of repository using interval VCS methods

    :param form_data:
    :param cur_user:
    """
    from rhodecode.model.repo import RepoModel
    from rhodecode.model.user import UserModel

    log = get_logger(create_repo_fork)
    DBS = get_session()

    base_path = Repository.base_path()
    cur_user = UserModel(DBS)._get_user(cur_user)

    fork_name = form_data['repo_name_full']
    repo_type = form_data['repo_type']
    description = form_data['description']
    owner = cur_user
    private = form_data['private']
    clone_uri = form_data.get('clone_uri')
    repos_group = form_data['repo_group']
    landing_rev = form_data['landing_rev']
    copy_fork_permissions = form_data.get('copy_permissions')
    fork_of = RepoModel(DBS)._get_repo(form_data.get('fork_parent_id'))

    fork_repo = RepoModel(DBS).create_repo(
        fork_name,
        repo_type,
        description,
        owner,
        private,
        clone_uri,
        repos_group,
        landing_rev,
        just_db=True,
        fork_of=fork_of,
        copy_fork_permissions=copy_fork_permissions)

    update_after_clone = form_data['update_after_clone']

    source_repo_path = os.path.join(base_path, fork_of.repo_name)
    destination_fork_path = os.path.join(base_path, fork_name)

    log.info('creating fork of %s as %s', source_repo_path,
             destination_fork_path)
    backend = get_backend(repo_type)

    if repo_type == 'git':
        r = backend(safe_str(destination_fork_path),
                    create=True,
                    src_url=safe_str(source_repo_path),
                    update_after_clone=update_after_clone,
                    bare=True)
        # add rhodecode hook into this repo
        ScmModel().install_git_hook(repo=r)
    elif repo_type == 'hg':
        r = backend(safe_str(destination_fork_path),
                    create=True,
                    src_url=safe_str(source_repo_path),
                    update_after_clone=update_after_clone)
    else:
        raise Exception('Unknown backend type %s' % repo_type)

    log_create_repository(fork_repo.get_dict(), created_by=cur_user.username)

    action_logger(cur_user, 'user_forked_repo:%s' % fork_name,
                  fork_of.repo_name, '', DBS)

    action_logger(cur_user, 'user_created_fork:%s' % fork_name, fork_name, '',
                  DBS)
    # finally commit at latest possible stage
    DBS.commit()
    fork_repo.update_changeset_cache()
 def get_backend(self):
     return vcs.get_backend(self.backend_alias)
def test_get_backend():
    hg = get_backend('hg')
    assert hg == MercurialRepository
 def get_backend(self):
     return vcs.get_backend(self.backend_alias)
def test_alias_detect_hg():
    alias = 'hg'
    path = TEST_HG_REPO
    backend = get_backend(alias)
    repo = backend(path)
    assert 'hg' == repo.alias
Example #22
0
 def get_backend(cls):
     return vcs.get_backend(cls.backend_alias)
Example #23
0
 def branch(self):
     return get_backend(self.alias).DEFAULT_BRANCH_NAME
Example #24
0
def create_repo_fork(form_data, cur_user):
    """
    Creates a fork of repository using interval VCS methods

    :param form_data:
    :param cur_user:
    """
    from rhodecode.model.repo import RepoModel
    from rhodecode.model.user import UserModel

    log = get_logger(create_repo_fork)
    DBS = get_session()

    base_path = Repository.base_path()
    cur_user = UserModel(DBS)._get_user(cur_user)

    fork_name = form_data['repo_name_full']
    repo_type = form_data['repo_type']
    description = form_data['description']
    owner = cur_user
    private = form_data['private']
    clone_uri = form_data.get('clone_uri')
    repos_group = form_data['repo_group']
    landing_rev = form_data['landing_rev']
    copy_fork_permissions = form_data.get('copy_permissions')
    fork_of = RepoModel(DBS)._get_repo(form_data.get('fork_parent_id'))

    fork_repo = RepoModel(DBS).create_repo(
        fork_name, repo_type, description, owner, private, clone_uri,
        repos_group, landing_rev, just_db=True, fork_of=fork_of,
        copy_fork_permissions=copy_fork_permissions
    )

    update_after_clone = form_data['update_after_clone']

    source_repo_path = os.path.join(base_path, fork_of.repo_name)
    destination_fork_path = os.path.join(base_path, fork_name)

    log.info('creating fork of %s as %s', source_repo_path,
             destination_fork_path)
    backend = get_backend(repo_type)

    if repo_type == 'git':
        backend(safe_str(destination_fork_path), create=True,
                src_url=safe_str(source_repo_path),
                update_after_clone=update_after_clone,
                bare=True)
    elif repo_type == 'hg':
        backend(safe_str(destination_fork_path), create=True,
                src_url=safe_str(source_repo_path),
                update_after_clone=update_after_clone)
    else:
        raise Exception('Unknown backend type %s' % repo_type)

    log_create_repository(fork_repo.get_dict(), created_by=cur_user.username)

    action_logger(cur_user, 'user_forked_repo:%s' % fork_name,
                   fork_of.repo_name, '', DBS)

    action_logger(cur_user, 'user_created_fork:%s' % fork_name,
                   fork_name, '', DBS)
    # finally commit at latest possible stage
    DBS.commit()
def test_alias_detect_git():
    alias = 'git'
    path = TEST_GIT_REPO
    backend = get_backend(alias)
    repo = backend(path)
    assert 'git' == repo.alias
def test_wrong_alias():
    alias = 'wrong_alias'
    with pytest.raises(VCSError):
        get_backend(alias)