fix publishing

master
nathaniel smith 2017-09-23 01:04:40 -07:00
parent 0c70b043d0
commit 457d2b2436
3 changed files with 26 additions and 21 deletions

View File

@ -18,8 +18,6 @@ def compile_wiki(source_path: str, dest_path: str) -> None:
Be absolutely sure you know what you are doing when you call this ^_^ Be absolutely sure you know what you are doing when you call this ^_^
""" """
# TODO progress bar # TODO progress bar
# TODO recursively delete dest_path (maybe after gzipping, backing up)
# TODO lockfile on dest_path
# TODO put useful metadata in footer # TODO put useful metadata in footer
header_content = compile_markdown(path_join(source_path, 'src/header.md')) header_content = compile_markdown(path_join(source_path, 'src/header.md'))
@ -35,7 +33,6 @@ def compile_wiki(source_path: str, dest_path: str) -> None:
current_suffix = current_suffix[1:] current_suffix = current_suffix[1:]
preview_root = path_join(dest_path, current_suffix) preview_root = path_join(dest_path, current_suffix)
for directory in dirs: for directory in dirs:
os.mkdir(path_join(preview_root, directory)) os.mkdir(path_join(preview_root, directory))

View File

@ -1,34 +1,40 @@
import git as gitpython import git as gitpython
import pygit2 import pygit2
# it's fucking weird to be using two different git libraries, i know.
# gitpython:
# - couldn't figure out how to check repo status
# pygit2:
# - had trouble with committing after a merge
# - can't push to local repos
#
# i want to standardize on gitpython, but gotta figure out the repo status and
# also do the cloning
def create_repo(to_clone, local_path, author_name, author_email): def create_repo(to_clone, local_path, author_name, author_email):
# TODO port to GitPython
repo = pygit2.clone_repository(to_clone, local_path) repo = pygit2.clone_repository(to_clone, local_path)
repo.config['user.name'] = author_name repo.config['user.name'] = author_name
repo.config['user.email'] = author_email repo.config['user.email'] = author_email
def dirty(repo_path):
# TODO figure out how to do with GitPython
repo = pygit2.Repository(repo_path)
return repo.status() == {}
def make_commit(repo_path, author_name, author_email): def make_commit(repo_path, author_name, author_email):
"""Given a path to a repository, adds everything and commits it. If there """Given a path to a repository, adds everything and commits it. If there
are no unstaged changes, does nothing.""" are no unstaged changes, does nothing."""
# TODO do nothing if no changes if not dirty(repo_path):
repo = pygit2.Repository(repo_path) return
repo.index.add_all() repo = gitpython.Repo(repo_path)
repo.index.write() index = repo.index
tree = repo.index.write_tree()
author = pygit2.Signature(author_name, author_email) index.add([path for (path, _), __ in index.entries.items()])
committer = pygit2.Signature(author_name, author_email)
oid = repo.create_commit( actor = gitpython.Actor(author_name, author_email)
'refs/head/master', index.commit('wiki update', author=actor, committer=actor)
author,
committer,
'wiki update'.format(author_name),
tree,
[repo.head.get_object().hex])
repo.reset(oid, pygit2.GIT_RESET_HARD)
# These next two functions use GitPython because libgit2 was having issues with
# a local repo. it sucks. honestly this is a more pleasant interface anyway so
# i might eventually just use GitPython.
def push_all(repo_path): def push_all(repo_path):
repo = gitpython.Repo(repo_path) repo = gitpython.Repo(repo_path)
repo.remotes['origin'].push() repo.remotes['origin'].push()

View File

@ -159,6 +159,8 @@ def publish(config, local_repo_path):
raise ClickException('Could not remove some paths: {}'.format(rm_error_paths)) raise ClickException('Could not remove some paths: {}'.format(rm_error_paths))
compile_wiki(config.repo_path, config.publish_path) compile_wiki(config.repo_path, config.publish_path)
except ClickException:
raise
except Exception as e: except Exception as e:
error = e error = e
finally: finally: