forked from benhoskings/babushka-deps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
git.rb
77 lines (71 loc) · 2.5 KB
/
git.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
dep 'git-aliases' do
requires 'git', 'git-user-config'
met? {
met_result = false
tmp_path = "/tmp/git-aliases-test"
shell("mkdir #{tmp_path}; cd #{tmp_path}; git init; touch foo")
cd(tmp_path) do
met_result = ["git st", "git br", "git add .; git ci -am 'foo'", "git co ."].all? do |alias_check|
raw_shell(alias_check).stderr.empty?
end
end
system("rm -rf #{tmp_path}")
met_result
}
meet {
log_shell "Adding git alias ci for commit", "git config --global alias.ci commit"
log_shell "Adding git alias co for checkout", "git config --global alias.co checkout"
log_shell "Adding git alias br for branch", "git config --global alias.br branch"
log_shell "Adding git alias st for status", "git config --global alias.st status"
}
end
dep 'git-user-config' do
requires 'git'
met? {
["git config --get user.email", "git config --get user.name"].all? do |cmd|
raw_shell(cmd).ok?
end
}
meet {
log_shell "Adding git config user.email", "git config --global user.email protonet@localhost"
log_shell "Adding git config user.name", 'git config --global user.name "protonet"'
}
end
dep 'passenger deploy repo' do
requires 'passenger deploy repo exists', 'passenger deploy repo hooks', 'passenger deploy repo always receives'
end
dep 'passenger deploy repo always receives' do
requires 'passenger deploy repo exists'
met? { cd(var(:passenger_repo_root)) { shell("git config receive.denyCurrentBranch") == 'ignore' } }
meet { cd(var(:passenger_repo_root)) { shell("git config receive.denyCurrentBranch ignore") } }
end
dep 'passenger deploy repo hooks' do
requires 'passenger deploy repo exists'
met? {
%w[pre-receive post-receive].all? {|hook_name|
(var(:passenger_repo_root) / ".git/hooks/#{hook_name}").executable?
}
}
meet {
cd var(:passenger_repo_root), :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 'passenger deploy repo exists' do
requires 'git'
define_var :passenger_repo_root, :default => :rails_root
met? { (var(:passenger_repo_root) / '.git').dir? }
meet {
cd var(:passenger_repo_root), :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