Alternative Adapter for grack; uses the RJGit gem for a pure jruby interface to git repos. Together with Grack, this yields a pure jruby implementation of git's smart-http protocol.
gem install rjgit_grack
- Get grack.
- add
grack
andrjgit_grack
to yourGemfile
- You can tell Grack to use the
RJGitAdapter
by editing its configuration, for example:
require 'grack/app'
require 'grack/rjgit_adapter'
config = {
:root => '/tmp/',
:allow_push => true,
:allow_pull => true,
:git_adapter_factory => ->{ Grack::RJGitAdapter.new }
}
run Grack::App.new(config)
This adapter allows you to specify hooks to be called when receive operations (i.e. git push
to the server) or upload operations (e.g. pulls, clones) are initiated. You can easily do this by passing an options hash to the Grack::RJGitAdapter.new
call in the configuration, like so:
:git_adapter_factory => ->{ Grack::RJGitAdapter.new({
:preReceive => Proc.new do |received_refs|
# This code is executed in the hook
puts received_refs
end
}
)}
You can specify the following hooks:
:preReceive
executed immediately before a receive-operation is performed. Yields anArray
withHash
objects containing info about each ref that is about to be pushed, of the following form:{:ref_name => 'refs/heads/masters', :old_id => 'somesha1', :new_id => 'someothersha1', :type => "FAST_FORWARD"}
:postReceive
executed after a receive-operation is completed. Yields anArray
withHash
objects for each ref that was pushed, of the same form as above, plus a:result
field. The result will be aString
, and can have one of the values defined by JGit.:preUpload
executed immediately before an upload-operation is performed, i.e. before data is sent to the client. Yields anArray
ofString
object-id's (SHA1-hashes) already in common between client and server.:postUpload
executed after an upload-operation to a client is complete. Returns anorg.eclipse.jgit.storage.pack.PackStatistics
object (see here).
Note that JGit blocks all read and write operations on the repository until a hook is complete, so the hooks should only contain code that runs quickly (e.g. running workers or threads to perform the heavy work).
Run the specs:
rake
(The MIT License)
Copyright (c) 2013 Dawa Ometto <d.ometto@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.