-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathgit_manager.rb
69 lines (56 loc) · 1.53 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
require 'logging'
# Lightweight wrapper over Git, shells out everything.
class GitManager
include Logging
attr_reader :basedir
def initialize(basedir)
@basedir = File.expand_path(basedir)
end
def remote_rails_url
'https://github.com/rails/rails.git'
end
def update_master
Dir.chdir(basedir) do
unless Dir.exists?('master')
log "cloning master into #{basedir}/master"
system "git clone -q #{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.
system 'git checkout Gemfile.lock'
system 'git pull -q'
end
end
end
def checkout(tag)
Dir.chdir(basedir) do
log "checking out tag #{tag}"
system "git clone -q #{remote_rails_url} #{tag}"
Dir.chdir(tag) do
system "git checkout -q #{tag}"
end
end
end
def release_tags
Dir.chdir("#{basedir}/master") do
`git tag`.scan(/^v[\d.]+$/)
end
end
def tag_date(tag)
Dir.chdir("#{basedir}/master") do
`git for-each-ref --format="%(taggerdate:iso8601)" refs/tags/#{tag}`.chomp
end
end
def short_sha1
sha1[0, 7]
end
def sha1
Dir.chdir("#{basedir}/master") do
`git rev-parse HEAD`.chomp
end
end
end