-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgit_manager.rb
70 lines (57 loc) · 1.61 KB
/
git_manager.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
require 'logging'
require 'running'
# Lightweight wrapper over Git, shells out everything.
class GitManager
include Logging
include Running
attr_reader :basedir
def initialize(basedir, verbose: false)
@basedir = File.expand_path(basedir)
@verbose = verbose
end
def q_unless_verbose
@verbose ? "" : "-q"
end
def remote_rails_url
'https://github.com/rails/rails.git'
end
def update_master
Dir.chdir(basedir) do
unless Dir.exist?('master')
log "cloning master into #{basedir}/master"
log_and_system "git clone #{q_unless_verbose} #{remote_rails_url} master"
end
Dir.chdir('master') do
log 'updating master'
# Bundler may modify BUNDLED WITH in Gemfile.lock and that may prevent
# git pull from succeeding. Starting with Bundler 1.10, if Gemfile.lock
# does not change BUNDLED WITH is left as is, even if versions differ,
# but since docs generation is automated better play safe.
log_and_system 'git checkout Gemfile.lock'
log_and_system "git pull #{q_unless_verbose}"
end
end
end
def checkout(tag)
Dir.chdir(basedir) do
log "checking out tag #{tag}"
log_and_system "git clone #{q_unless_verbose} #{remote_rails_url} #{tag}"
Dir.chdir(tag) do
log_and_system "git checkout #{q_unless_verbose} #{tag}"
end
end
end
def release_tags
Dir.chdir("#{basedir}/master") do
`git tag`.scan(/^v[\d.]+$/)
end
end
def short_sha1
sha1[0, 7]
end
def sha1
Dir.chdir("#{basedir}/master") do
`git rev-parse HEAD`.chomp
end
end
end