Skip to content

Instantly share code, notes, and snippets.

@urlsangel
Created April 18, 2013 08:15
Show Gist options
  • Save urlsangel/5411081 to your computer and use it in GitHub Desktop.
Save urlsangel/5411081 to your computer and use it in GitHub Desktop.
Automatically syncing Gollum wiki when used as a web service. I've added the lines at 43, 44 to do a pull/push on the repo to automatically sync on git commit. Is there a cleaner way to do this? And what are the potential issues regarding conflicts?
# Public: Write a new version of a page to the Gollum repo root.
#
# name - The String name of the page.
# format - The Symbol format of the page.
# data - The new String contents of the page.
# commit - The commit Hash details:
# :message - The String commit message.
# :name - The String author full name.
# :email - The String email address.
# :parent - Optional Grit::Commit parent to this update.
# :tree - Optional String SHA of the tree to create the
# index from.
# :committer - Optional Gollum::Committer instance. If provided,
# assume that this operation is part of batch of
# updates and the commit happens later.
# dir - The String subdirectory of the Gollum::Page without any
# prefix or suffix slashes (e.g. "foo/bar").
# Returns the String SHA1 of the newly written version, or the
# Gollum::Committer instance if this is part of a batch update.
def write_page(name, format, data, commit = {}, dir = '')
# spaces must be dashes
name.gsub!(' ', '-')
dir.gsub!(' ', '-')
multi_commit = false
committer = if obj = commit[:committer]
multi_commit = true
obj
else
Committer.new(self, commit)
end
filename = Gollum::Page.cname(name)
committer.add_to_index(dir, filename, format, data)
committer.after_commit do |index, sha|
@access.refresh
index.update_working_dir(dir, filename, format)
# added to automate syncing
@repo.git.native('pull')
@repo.git.native('push')
end
multi_commit ? committer : committer.commit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment