forked from cristibalan/braid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rspec_git.rb
159 lines (138 loc) · 4.11 KB
/
rspec_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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
module RSpec
class Git
attr_reader :name, :path, :url
def initialize(name, path, url)
@name = name
@path = path
@url = url
end
def msg(str)
puts "RSpec: #{str}"
end
def plugins_fetched?
submodules.all? {|s| File.directory?(s[:path]) }
end
def update(target)
check_for_clean_repos "Unable to update"
repos.each do |r|
if File.exist?(r[:path])
msg "** Updating #{r[:name]}"
target = target ? target : "master"
# unless system("cd #{r[:path]} && git pull --rebase #{target}")
unless system("cd #{r[:path]} && git pull --rebase #{r[:url]} #{target}")
msg "Error updating #{r[:name]}"
exit 1
end
else
msg "** Fetching #{r[:name]}"
system "git clone #{r[:url]} #{r[:path]}"
end
end
msg "*** all repos updated successfully ***"
end
def status
repos.each do |r|
msg "\n** #{r[:name]} status"
system "cd #{r[:path]} && git status"
end
end
def push
check_for_clean_repos "Unable to push"
repos.each do |r|
msg "** push #{r[:name]}"
unless system("cd #{r[:path]} && git push && git push --tags")
msg "Error pushing #{r[:name]}"
exit 1
end
end
msg "Successfully pushed changes to github"
end
def commit
if ENV['MESSAGE'].nil?
msg "You must pass a commit message. Try it again with:\n" +
"rake git:commit MESSAGE='commit message here'"
return
end
repos.each do |r|
output = `cd #{r[:path]} && git status`
unless output.include?('On branch master')
msg "*** #{r[:name]} is not on the master branch. Skipping"
next
end
msg "** Committing #{r[:name]}"
system "cd #{r[:path]} && git commit -a -m #{ENV['MESSAGE'].inspect}"
end
end
def hard_reset
repos.each do |r|
msg "\n** Resetting #{r[:name]}"
system "cd #{r[:path]} && git add . && git reset --hard"
end
msg
end
def add_remotes
if ENV['REPO_PREFIX'].nil? || ENV['NAME'].nil?
msg "You must pass a prefix and name. Try it again with (e.g.):\n" +
"rake git:add_remotes REPO_PREFIX='git://github.com/dchelimsky' NAME='dc'"
return
end
repos.each do |r|
system "cd #{r[:path]} && git remote add #{ENV['NAME']} #{r[:url]}"
end
end
def tag
if ENV['TAG'].nil?
msg "You must pass a tag. Try again like so:\n" +
" TAG=1.1.4 rake git:tag"
return
end
repos.each do |r|
system "cd #{r[:path]} && git tag #{ENV['TAG']}"
end
end
private
def check_for_clean_repos(message)
unless all_repos_clean?
msg "*** #{message} ***"
status
exit 1
end
end
def all_repos_clean?
repos.all? do |r|
!File.exist?(r[:path]) ||
(output = `cd #{r[:path]} && git status`;
output.include?('On branch master') &&
!output.include?('Changes to be committed:') &&
!output.include?('Changed but not updated:'))
end
end
def repos
# [submodules, superproject].flatten
[ {:name => @name, :path => @path, :url => @url} ]
end
# def superproject
# {:name => "rspec-dev", :path => ".",
# :url => "#{url_prefix}/rspec-dev.git"}
# end
# def submodules
# [
# {:name => "TextMate Bundle", :path => 'RSpec.tmbundle',
# :url => "#{url_prefix}/rspec-tmbundle.git" },
# {:name => "rspec", :path => 'example_rails_app/vendor/plugins/rspec',
# :url => "#{url_prefix}/rspec.git"},
# {:name => "rspec-rails", :path => 'example_rails_app/vendor/plugins/rspec-rails',
# :url => "#{url_prefix}/rspec-rails.git"}
# ]
# end
def url_prefix
if ENV["COMMITTER"]
"git@github.com:dreamcat4"
elsif ENV["REPO_PREFIX"]
ENV["REPO_PREFIX"]
else
"git://github.com/dreamcat4"
end
end
end
end