Ejemplo n.º 1
0
    def url_handler(repo_type, url, ui=None):
        if repo_type == 'hg':
            from rhodecode.lib.vcs.backends.hg.repository import MercurialRepository
            from mercurial.httppeer import httppeer
            if url.startswith('http'):
                ## initially check if it's at least the proper URL
                ## or does it pass basic auth
                MercurialRepository._check_url(url)
                httppeer(ui, url)._capabilities()
            elif url.startswith('svn+http'):
                from hgsubversion.svnrepo import svnremoterepo
                svnremoterepo(ui, url).capabilities
            elif url.startswith('git+http'):
                raise NotImplementedError()
            else:
                raise Exception('clone from URI %s not allowed' % (url))

        elif repo_type == 'git':
            from rhodecode.lib.vcs.backends.git.repository import GitRepository
            if url.startswith('http'):
                ## initially check if it's at least the proper URL
                ## or does it pass basic auth
                GitRepository._check_url(url)
            elif url.startswith('svn+http'):
                raise NotImplementedError()
            elif url.startswith('hg+http'):
                raise NotImplementedError()
            else:
                raise Exception('clone from URI %s not allowed' % (url))
def test_git_sets_default_branch_if_not_master(backend_git, tmpdir,
                                               disable_locking, rc_web_server):
    empty_repo = backend_git.create_repo()
    clone_url = rc_web_server.repo_clone_url(empty_repo.repo_name)

    cmd = Command(tmpdir.strpath)
    cmd.execute('git clone', clone_url)

    repo = GitRepository(os.path.join(tmpdir.strpath, empty_repo.repo_name))
    repo.in_memory_commit.add(FileNode('file', content=''))
    repo.in_memory_commit.commit(message='Commit on branch test',
                                 author='Automatic test',
                                 branch='test')

    repo_cmd = Command(repo.path)
    stdout, stderr = repo_cmd.execute('git push --verbose origin test')
    _check_proper_git_push(stdout,
                           stderr,
                           branch='test',
                           should_set_default_branch=True)

    stdout, stderr = cmd.execute('git clone', clone_url,
                                 empty_repo.repo_name + '-clone')
    _check_proper_clone(stdout, stderr, 'git')

    # Doing an explicit commit in order to get latest user logs on MySQL
    Session().commit()
    def url_handler(repo_type, url):
        config = make_db_config(clear_session=False)
        if repo_type == 'hg':
            allowed_prefixes = ('http', 'svn+http', 'git+http')

            if 'http' in url[:4]:
                # initially check if it's at least the proper URL
                # or does it pass basic auth
                MercurialRepository.check_url(url, config)
            elif 'svn+http' in url[:8]:  # svn->hg import
                SubversionRepository.check_url(url, config)
            elif 'git+http' in url[:8]:  # git->hg import
                raise NotImplementedError()
            else:
                exc = InvalidCloneUrl('Clone from URI %s not allowed. '
                                      'Allowed url must start with one of %s'
                                      % (url, ','.join(allowed_prefixes)))
                exc.allowed_prefixes = allowed_prefixes
                raise exc

        elif repo_type == 'git':
            allowed_prefixes = ('http', 'svn+http', 'hg+http')
            if 'http' in url[:4]:
                # initially check if it's at least the proper URL
                # or does it pass basic auth
                GitRepository.check_url(url, config)
            elif 'svn+http' in url[:8]:  # svn->git import
                raise NotImplementedError()
            elif 'hg+http' in url[:8]:  # hg->git import
                raise NotImplementedError()
            else:
                exc = InvalidCloneUrl('Clone from URI %s not allowed. '
                                      'Allowed url must start with one of %s'
                                      % (url, ','.join(allowed_prefixes)))
                exc.allowed_prefixes = allowed_prefixes
                raise exc
Ejemplo n.º 4
0
def check_git_version():
    """
    Checks what version of git is installed in system, and issues a warning
    if it's too old for RhodeCode to properly work.
    """
    from rhodecode import BACKENDS
    from rhodecode.lib.vcs.backends.git.repository import GitRepository
    from rhodecode.lib.vcs.conf import settings
    from distutils.version import StrictVersion

    stdout, stderr = GitRepository._run_git_command('--version',
                                                    _bare=True,
                                                    _safe=True)

    ver = (stdout.split(' ')[-1] or '').strip() or '0.0.0'
    if len(ver.split('.')) > 3:
        #StrictVersion needs to be only 3 element type
        ver = '.'.join(ver.split('.')[:3])
    try:
        _ver = StrictVersion(ver)
    except Exception:
        _ver = StrictVersion('0.0.0')
        stderr = traceback.format_exc()

    req_ver = '1.7.4'
    to_old_git = False
    if _ver < StrictVersion(req_ver):
        to_old_git = True

    if 'git' in BACKENDS:
        log.debug('GIT executable: "%s" version detected: %s' %
                  (settings.GIT_EXECUTABLE_PATH, stdout))
        if stderr:
            log.warning('Unable to detect git version, org error was: %r' %
                        stderr)
        elif to_old_git:
            log.warning('RhodeCode detected git version %s, which is too old '
                        'for the system to function properly. Make sure '
                        'its version is at least %s' % (ver, req_ver))
    return _ver
Ejemplo n.º 5
0
def check_git_version():
    """
    Checks what version of git is installed in system, and issues a warning
    if it's too old for RhodeCode to properly work.
    """
    from rhodecode import BACKENDS
    from rhodecode.lib.vcs.backends.git.repository import GitRepository
    from rhodecode.lib.vcs.conf import settings
    from distutils.version import StrictVersion

    stdout, stderr = GitRepository._run_git_command('--version', _bare=True,
                                                    _safe=True)

    ver = (stdout.split(' ')[-1] or '').strip() or '0.0.0'
    if len(ver.split('.')) > 3:
        #StrictVersion needs to be only 3 element type
        ver = '.'.join(ver.split('.')[:3])
    try:
        _ver = StrictVersion(ver)
    except Exception:
        _ver = StrictVersion('0.0.0')
        stderr = traceback.format_exc()

    req_ver = '1.7.4'
    to_old_git = False
    if  _ver < StrictVersion(req_ver):
        to_old_git = True

    if 'git' in BACKENDS:
        log.debug('GIT executable: "%s" version detected: %s'
                  % (settings.GIT_EXECUTABLE_PATH, stdout))
        if stderr:
            log.warning('Unable to detect git version, org error was: %r' % stderr)
        elif to_old_git:
            log.warning('RhodeCode detected git version %s, which is too old '
                        'for the system to function properly. Make sure '
                        'its version is at least %s' % (ver, req_ver))
    return _ver