forked from tildetown/tilde-wiki
fix publishing
parent
0c70b043d0
commit
457d2b2436
|
@ -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 ^_^
|
||||
"""
|
||||
# TODO progress bar
|
||||
# TODO recursively delete dest_path (maybe after gzipping, backing up)
|
||||
# TODO lockfile on dest_path
|
||||
# TODO put useful metadata in footer
|
||||
|
||||
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:]
|
||||
preview_root = path_join(dest_path, current_suffix)
|
||||
|
||||
|
||||
for directory in dirs:
|
||||
os.mkdir(path_join(preview_root, directory))
|
||||
|
||||
|
|
|
@ -1,34 +1,40 @@
|
|||
import git as gitpython
|
||||
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):
|
||||
# TODO port to GitPython
|
||||
repo = pygit2.clone_repository(to_clone, local_path)
|
||||
repo.config['user.name'] = author_name
|
||||
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):
|
||||
"""Given a path to a repository, adds everything and commits it. If there
|
||||
are no unstaged changes, does nothing."""
|
||||
# TODO do nothing if no changes
|
||||
repo = pygit2.Repository(repo_path)
|
||||
repo.index.add_all()
|
||||
repo.index.write()
|
||||
tree = repo.index.write_tree()
|
||||
author = pygit2.Signature(author_name, author_email)
|
||||
committer = pygit2.Signature(author_name, author_email)
|
||||
oid = repo.create_commit(
|
||||
'refs/head/master',
|
||||
author,
|
||||
committer,
|
||||
'wiki update'.format(author_name),
|
||||
tree,
|
||||
[repo.head.get_object().hex])
|
||||
repo.reset(oid, pygit2.GIT_RESET_HARD)
|
||||
if not dirty(repo_path):
|
||||
return
|
||||
repo = gitpython.Repo(repo_path)
|
||||
index = repo.index
|
||||
|
||||
index.add([path for (path, _), __ in index.entries.items()])
|
||||
|
||||
actor = gitpython.Actor(author_name, author_email)
|
||||
index.commit('wiki update', author=actor, committer=actor)
|
||||
|
||||
# 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):
|
||||
repo = gitpython.Repo(repo_path)
|
||||
repo.remotes['origin'].push()
|
||||
|
|
|
@ -159,6 +159,8 @@ def publish(config, local_repo_path):
|
|||
raise ClickException('Could not remove some paths: {}'.format(rm_error_paths))
|
||||
|
||||
compile_wiki(config.repo_path, config.publish_path)
|
||||
except ClickException:
|
||||
raise
|
||||
except Exception as e:
|
||||
error = e
|
||||
finally:
|
||||
|
|
Loading…
Reference in New Issue