How to use the mike.git_utils.Commit function in mike

To help you get started, we’ve selected a few mike 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 jimporter / mike / test / integration / test_deploy.py View on Github external
def test_remote_empty(self):
        stage_dir('deploy_clone')
        check_call_silent(['git', 'clone', self.stage, '.'])
        git_config()

        with git_utils.Commit('gh-pages', 'add file') as commit:
            commit.add_file(git_utils.FileInfo(
                'file.txt', 'this is some text'
            ))
        old_rev = git_utils.get_latest_commit('gh-pages')

        assertPopen(['mike', 'deploy', '1.0'])
        self.assertEqual(git_utils.get_latest_commit('gh-pages^'), old_rev)
github jimporter / mike / test / integration / test_serve.py View on Github external
def test_behind_remote(self):
        stage_dir('serve_clone')
        check_call_silent(['git', 'clone', self.stage, '.'])
        check_call_silent(['git', 'fetch', 'origin', 'gh-pages:gh-pages'])
        git_config()

        with pushd(self.stage):
            with git_utils.Commit('gh-pages', 'add file') as commit:
                commit.add_file(git_utils.FileInfo(
                    'file.txt', 'this is some text'
                ))
            origin_rev = git_utils.get_latest_commit('gh-pages')
        check_call_silent(['git', 'fetch', 'origin'])

        self._check_serve()
        self.assertEqual(git_utils.get_latest_commit('gh-pages'), origin_rev)
github jimporter / mike / test / unit / test_server.py View on Github external
def setUp(self):
        self.stage = stage_dir('server')
        git_init()
        with git_utils.Commit('branch', 'add file') as commit:
            commit.add_file(git_utils.FileInfo('index.html', 'main page'))
            commit.add_file(git_utils.FileInfo('dir/index.html', 'sub page'))

        class Handler(server.GitBranchHTTPHandler):
            branch = 'branch'

            # Use a buffered response in Python 3.6+, since it's easier for
            # testing.
            if sys.version_info >= (3, 6):
                wbufsize = -1

            def log_message(self, *args):
                pass

        self.server = MockServer(('0.0.0.0', 8888), Handler)
github jimporter / mike / test / integration / test_deploy.py View on Github external
'file.txt', 'this is some text'
            ))

        stage_dir('deploy_clone')
        check_call_silent(['git', 'clone', self.stage, '.'])
        check_call_silent(['git', 'fetch', 'origin', 'gh-pages:gh-pages'])
        git_config()

        with pushd(self.stage):
            with git_utils.Commit('gh-pages', 'add file') as commit:
                commit.add_file(git_utils.FileInfo(
                    'file2-origin.txt', 'this is some text'
                ))
            origin_rev = git_utils.get_latest_commit('gh-pages')

        with git_utils.Commit('gh-pages', 'add file') as commit:
            commit.add_file(git_utils.FileInfo(
                'file2.txt', 'this is some text'
            ))
        clone_rev = git_utils.get_latest_commit('gh-pages')
        check_call_silent(['git', 'fetch', 'origin'])

        assertOutput(self, ['mike', 'deploy', '1.0'], output=(
            'mike: gh-pages has diverged from origin/gh-pages\n' +
            '  Pass --ignore to ignore this or --rebase to rebase onto ' +
            'remote\n'
        ), returncode=1)
        self.assertEqual(git_utils.get_latest_commit('gh-pages'), clone_rev)

        assertPopen(['mike', 'deploy', '--ignore', '1.0'])
        self.assertEqual(git_utils.get_latest_commit('gh-pages^'), clone_rev)
github jimporter / mike / test / integration / test_serve.py View on Github external
def test_diverged_remote(self):
        stage_dir('serve_clone')
        check_call_silent(['git', 'clone', self.stage, '.'])
        check_call_silent(['git', 'fetch', 'origin', 'gh-pages:gh-pages'])
        git_config()

        with pushd(self.stage):
            with git_utils.Commit('gh-pages', 'add file') as commit:
                commit.add_file(git_utils.FileInfo(
                    'file-origin.txt', 'this is some text'
                ))
            origin_rev = git_utils.get_latest_commit('gh-pages')

        with git_utils.Commit('gh-pages', 'add file') as commit:
            commit.add_file(git_utils.FileInfo(
                'file.txt', 'this is some text'
            ))
        clone_rev = git_utils.get_latest_commit('gh-pages')
        check_call_silent(['git', 'fetch', 'origin'])

        self._check_serve(err_output=(
            'warning: gh-pages has diverged from origin/gh-pages\n' +
            '  Pass --ignore to ignore this or --rebase to rebase onto ' +
            'remote\n'
        ))
        self.assertEqual(git_utils.get_latest_commit('gh-pages'), clone_rev)

        self._check_serve(['--ignore'])
        self.assertEqual(git_utils.get_latest_commit('gh-pages'), clone_rev)
github jimporter / mike / test / unit / test_git_utils.py View on Github external
def test_delete_all_files(self):
        self._add_file('file.txt')
        self._add_file('file2.txt')
        with git_utils.Commit('master', 'delete all files') as commit:
            commit.delete_files('*')

        check_call_silent(['git', 'checkout', 'master'])
        assertDirectory('.', set())
github jimporter / mike / test / unit / test_commands.py View on Github external
def setUp(self):
        self.stage = stage_dir('serve')
        git_init()
        with git_utils.Commit('branch', 'add file') as commit:
            commit.add_file(git_utils.FileInfo('index.html', 'main page'))
            commit.add_file(git_utils.FileInfo('dir/index.html', 'sub page'))
github jimporter / mike / test / unit / test_commands.py View on Github external
def test_overwrite_version(self):
        with git_utils.Commit('gh-pages', 'add versions.json') as commit:
            commit.add_file(git_utils.FileInfo(
                'versions.json',
                '[{"version": "1.0", "title": "1.0", "aliases": ["latest"]}]',
            ))
            commit.add_file(git_utils.FileInfo('1.0/old-file.txt', ''))
            commit.add_file(git_utils.FileInfo('latest/old-file.txt', ''))

        commands.deploy(self.stage, '1.0', '1.0.1', ['greatest'])
        check_call_silent(['git', 'checkout', 'gh-pages'])
        self._test_deploy(expected_versions=[
            versions.VersionInfo('1.0', '1.0.1', ['latest', 'greatest'])
        ])
github jimporter / mike / mike / commands.py View on Github external
if message is None:
        message = (
            'Copied {doc_version} to {aliases} with mike {mike_version}'
        ).format(
            doc_version=version,
            aliases=', '.join(aliases),
            mike_version=app_version
        )

    all_versions = list_versions(branch)
    try:
        destdirs = all_versions.update(version, aliases=aliases)
    except KeyError as e:
        raise ValueError('version {} does not exist'.format(e))

    with git_utils.Commit(branch, message) as commit:
        commit.delete_files(destdirs)

        for f in git_utils.walk_files(branch, version):
            for d in destdirs:
                commit.add_file(f.copy(d, version))
        commit.add_file(versions_to_file_info(all_versions))
github jimporter / mike / mike / commands.py View on Github external
def retitle(version, title, branch='gh-pages', message=None):
    if message is None:
        message = (
            'Set title of {doc_version} to {title} with mike {mike_version}'
        ).format(doc_version=version, title=title, mike_version=app_version)

    all_versions = list_versions(branch)
    try:
        all_versions.update(version, title)
    except KeyError:
        raise ValueError('version {} does not exist'.format(version))

    with git_utils.Commit(branch, message) as commit:
        commit.add_file(versions_to_file_info(all_versions))