Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
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)
'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)
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)
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())
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'))
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'])
])
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))
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))