Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Add an after commit hook for updating repo #12
I've been setting Gollum up on a little Debian box here so it can be used as a shared wiki resource. I'd like it to be able to accept wiki amends through either the web interface (a single centrally served one, not a localhost instance each), or through individual markdown edits and git commits.
For the web service to keep in sync though, I need it to do a pull/push on commit - I understand that this might create merge conflicts if someone else is editing that page at the same time, but I think the risk of that is low at the moment, and I can live with it.
I've created this gist of how I've hacked it to work at the moment:
I also need some way for the server to pull the latest whenever a new session is started.
I'm a Ruby noob so am feeling my way along in this - any thoughts on what the best way to do this would be?
That sounds like the way forward, however the post-commit hook is never fired (although works fine when run manually as www-data).
This is the contents of my .git/hooks/post-commit file (where /path/to is an actual path):
However, this never gets called - I've logged out to file from here, and it isn't that it fails, it just never seems to run after Gollum commits through the web interface.
The user is www-data, the file is executable, and I've added the following to sudoers:
www-data ALL=NOPASSWD: /path/to/.git/hooks/post-commit
I'm stumped - any help gratefully received.
I think there are definitely some advantages to supporting this functionality directly in
As an initial thought, this could be done in a similar way to how custom markups are registered (see gollum/gollum#637). Does anyone have a better suggestion?
I needed this functionality in gollum as well i.e. I wanted to push to a remote repo when changes were made to the wiki through the web interface.
I achieved this by adding a remote origin to the repository:
and then putting the following code into gollum/lib/gollum/app.rb:
after do wikip = wiki_page('home') wiki = wikip.wiki wiki.repo.git.push end
So that changes get pushed whenever a "do" fires.
This seems to work fine even when there is no remote origin defined.
pushed a commit
Aug 10, 2013
Forgive my ignorance, but how would one add the hooks to gollum's config.rb? Simply adding a block
Gollum::Hook.register(:post_commit, :hook_id) do |committer, sha1| #commands end
EDIT: I figured it out!
wiki = Gollum::Wiki.new(".") Gollum::Hook.register(:post_commit, :hook_id) do |committer, sha1| wiki.repo.git.pull wiki.repo.git.push end
@jason-sge I think it would be much better to do what you're trying to do by putting this into your config.rb file instead of what you have there:
since you have direct access to
By the way @jamieoliver this works like a charm, really awesome!
referenced this issue
Dec 16, 2014
The grit adapter has been updated. Here's the currently working hook with remote = origin and branch = master.
Actually the more correct way of doing this might be:
Gollum::Hook.register(:post_commit, :hook_id) do |committer, sha1| committer.wiki.repo.git.pull('origin', committer.wiki.ref) committer.wiki.repo.git.push('origin', committer.wiki.ref) end
So there would not be any need of creating an instance of wiki.