Skip to content

Commit

Permalink
Added git
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanvanderbyl committed Apr 16, 2012
1 parent 2b14ec1 commit 8032e7d
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
91 changes: 91 additions & 0 deletions git.rb
@@ -0,0 +1,91 @@
dep 'git.managed' do
requires 'ppa'.with('ppa:git-core/ppa')
installs 'git'
provides 'git >= 1.7.4.1'
end

dep 'git.src', :version do
version.default!('1.7.9')
source "http://git-core.googlecode.com/files/git-#{version}.tar.gz"
met? { in_path? "git >= #{version}" }
end

dep 'web repo', :path do
requires [
'web repo exists'.with(path),
'web repo hooks'.with(path),
'web repo always receives'.with(path),
'bundler.gem'
]
met? {
vanity_path = path.p.sub(/^#{Etc.getpwuid(Process.euid).dir.chomp('/')}/, '~')
log "All done. The repo's URI: " + "#{shell('whoami')}@#{shell('hostname -f')}:#{vanity_path}".colorize('underline')
true
}
end

dep 'web repo always receives', :path do
requires 'web repo exists'.with(path)
met? { cd(path) { shell?("git config receive.denyCurrentBranch") == 'ignore' } }
meet { cd(path) { shell("git config receive.denyCurrentBranch ignore") } }
end

dep 'web repo hooks', :path do
requires 'web repo exists'.with(path)
met? {
%w[pre-receive post-receive].all? {|hook_name|
(path / ".git/hooks/#{hook_name}").executable? &&
Babushka::Renderable.new(path / ".git/hooks/#{hook_name}").from?(dependency.load_path.parent / "git/deploy-repo-#{hook_name}")
}
}
meet {
cd path, :create => true do
%w[pre-receive post-receive].each {|hook_name|
render_erb "git/deploy-repo-#{hook_name}", :to => ".git/hooks/#{hook_name}"
shell "chmod +x .git/hooks/#{hook_name}"
}
end
}
end

dep 'web repo exists', :path do
requires 'git'
path.ask("Where should the repo be created").default("~/current")
met? { (path / '.git').dir? }
meet {
cd path, :create => true do
shell "git init"
end
}
end

dep 'github token set' do
met? { !shell('git config --global github.token').blank? }
meet { shell("git config --global github.token '#{var(:github_token)}'")}
end

dep 'pushed.repo' do
requires 'remote exists.repo'
setup { repo.repo_shell "git fetch #{var(:remote_name)}" }
met? {
repo.repo_shell("git rev-parse --short #{var(:deploy_ref)}") ==
repo.repo_shell("git rev-parse --short #{var(:remote_name)}/#{var(:deploy_ref)}")
}
meet { repo.repo_shell "git push #{var(:remote_name)} #{var(:deploy_ref)}", :log => true }
end

dep 'remote exists.repo' do
def remote_url
repo.repo_shell("git config remote.#{var(:remote_name)}.url")
end
met? { remote_url == var(:remote_url) }
meet {
if remote_url.blank?
log "The #{var(:remote_name)} remote isn't configured."
repo.repo_shell("git remote add #{var(:remote_name)} '#{var(:remote_url)}'")
elsif remote_url != var(:remote_url)
log "The #{var(:remote_name)} remote has a different URL (#{var(:remote_url)})."
repo.repo_shell("git remote set-url #{var(:remote_name)} '#{var(:remote_url)}'")
end
}
end
5 changes: 5 additions & 0 deletions git/deploy-repo-post-receive
@@ -0,0 +1,5 @@
#!/bin/bash

cd .. # up from .git/
unset GIT_DIR # otherwise `git` commands can't see other repos
babushka --colour 'benhoskings:up to date.repo' git_ref_data="$(cat /dev/stdin)"
5 changes: 5 additions & 0 deletions git/deploy-repo-pre-receive
@@ -0,0 +1,5 @@
#!/bin/bash

cd .. # up from .git/
unset GIT_DIR # otherwise `git` commands can't see other repos
babushka --colour 'benhoskings:ready for update.repo' git_ref_data="$(cat /dev/stdin)"

0 comments on commit 8032e7d

Please sign in to comment.