Skip to content

Instantly share code, notes, and snippets.

@seveas
Created October 27, 2013 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seveas/7187313 to your computer and use it in GitHub Desktop.
Save seveas/7187313 to your computer and use it in GitHub Desktop.
branch = repo.ref('heads/gh-pages')
parent = repo.commit(branch.object.sha)
files = os.listdir('.')
blobs = []
for (dir, _, files) in os.walk('.'):
dir = dir[2:]
for file in files:
with open(os.path.join(dir, file)) as fd:
sha = repo.create_blob(fd.read().encode('base64'), "base64")
blobs.append({'path': os.path.join(dir, file), 'mode': '100644', 'type': 'blob', 'sha': sha or empty_file_hash})
tree = repo.create_tree(blobs)
if tree.sha != parent.commit.tree.sha:
self.logger.info("Creating new commit")
commit = repo.create_commit("Automatic update from commit %s" % job.commit,
tree=tree.sha, parents=[parent.sha],
author={'name': 'Golem', 'email': 'golem@seveas.net'})
branch.update(commit.sha)
else:
self.logger.info("No change, not creating commit")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment