class Pebblescape::Receiver::Receiver
Attributes
app[RW]
app_path[RW]
home[RW]
Public Class Methods
new(command, app, commandline)
click to toggle source
# File lib/pebblescape/receiver.rb, line 16 def initialize(command, app, commandline) @app = app.gsub('\'', '') @home = env("HOME") @app_path = File.join(home, @app) # Pass through to git if command.start_with?("git-") if command == "git-receive-pack" && !repo_exists? setup_hook end exec_git(commandline) end deploy if command == "deploy" end
Public Instance Methods
deploy()
click to toggle source
# File lib/pebblescape/receiver.rb, line 33 def deploy old_rev, new_rev, ref_name = STDIN.gets.split if ref_name == "refs/heads/master" puts new_rev exit 1 else error("WARNING: deploy did not complete, you must push to master.") end end
exec_git(command)
click to toggle source
# File lib/pebblescape/receiver.rb, line 44 def exec_git(command) exec(user_env_hash, "git-shell -c #{command.join(" ").shellescape}") end
repo_exists?()
click to toggle source
# File lib/pebblescape/receiver.rb, line 61 def repo_exists? Dir.exists?(File.join(app_path, "refs")) end
setup_hook()
click to toggle source
# File lib/pebblescape/receiver.rb, line 48 def setup_hook run! "git init --bare #{app_path}" hook_path = File.join(app_path, "hooks", "pre-receive") hook = <<EOF #!/usr/bin/env bash set -e; set -o pipefail; cat | PEBBLES_ROOT="#{home}" pebblescape-receive deploy #{app} | sed -u "s/^/"$'\e[1G'"/" EOF File.open(hook_path, 'w+') { |f| f.write(hook) } File.chmod(0777, hook_path) end