This repository has been archived by the owner on Dec 24, 2019. It is now read-only.
/
babushka.rb
115 lines (105 loc) · 3.15 KB
/
babushka.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
meta :babushka do
def repo
Babushka::GitRepo.new(path)
end
end
dep 'babushka', :from, :path, :version, :branch do
ref = if branch.set?
deprecated! '2012-12-20', :method_name => "the :branch parameter to 'babushka'", :instead => ':version'
branch
else
version.default!('master')
end
requires 'up to date.babushka'.with(from, path, ref)
requires 'in path.babushka'.with(from, path)
path.ask("Where would you like babushka installed").default('/usr/local/babushka')
path.default!(Babushka::Path.path) if Babushka::Path.run_from_path?
end
dep 'up to date.babushka', :from, :path, :ref do
def qualified_ref
# Prepend "origin/" we're installing from scratch, or if the result is a
# valid remote branch.
if repo.exists? && repo.all_branches.include?("origin/#{ref}")
"origin/#{ref}"
else
ref
end
end
def refspec
repo.resolve(qualified_ref)
end
requires 'repo clean.babushka'.with(from, path)
requires 'resolvable ref.babushka'.with(from, path, qualified_ref)
met? {
(repo.current_head == refspec).tap {|result|
if result
log_ok "babushka is up to date at #{repo.current_head}."
else
log "babushka can be updated: #{repo.current_head}..#{refspec}"
end
}
}
meet {
log "#{repo.repo_shell("git diff --stat #{repo.current_head}..#{refspec}")}"
repo.detach!(refspec)
}
end
dep 'repo clean.babushka', :from, :path do
requires 'installed.babushka'.with(from, path)
met? {
repo.clean? or unmeetable!("There are local changes in #{repo.path}.")
}
end
dep 'resolvable ref.babushka', :from, :path, :ref do
met? {
if !@fetched && ref['origin/']
false # Always fetch before resolving a remote ref.
else
repo.resolve(ref).tap {|result|
if result
log_ok "#{ref} resolves to #{result}."
else
log "#{ref} doesn't resolve to a ref."
end
}
end
}
meet {
log_block "Fetching #{from}", :failure => "failed, check your internet connection." do
@fetched = true
repo.repo_shell?('git fetch origin')
end
}
end
dep 'in path.babushka', :from, :path do
requires 'installed.babushka'.with(from, path)
def bin_path
repo.path / '../bin'
end
setup {
unless ENV['PATH'].split(':').map {|p| p.chomp('/') }.include?(bin_path)
unmeetable! "The binary path alongside babushka, #{bin_path}, isn't in your $PATH."
end
}
met? { which 'babushka' }
prepare {
unmeetable! "The current user, #{shell('whoami')}, can't write to #{bin_path} (to symlink babushka into the path)." unless bin_path.hypothetically_writable?
}
meet {
bin_path.mkdir
log_shell "Linking babushka into #{bin_path}", %Q{ln -sf "#{repo.path / 'bin/babushka.rb'}" "#{bin_path / 'babushka'}"}
}
end
dep 'installed.babushka', :from, :path do
from.default!("https://github.com/benhoskings/babushka.git")
requires 'ruby', 'git'
setup {
unmeetable! "The current user, #{shell('whoami')}, can't write to #{repo.path}." unless repo.path.hypothetically_writable?
}
met? { repo.exists? }
meet {
log_block "Cloning #{from} into #{repo.path}" do
repo.clone! from
end
}
end