Repository navigation
Expand file tree
/
Copy pathcommand.rb
More file actions
108 lines (84 loc) · 2.55 KB
/
Copy pathcommand.rb
File metadata and controls
108 lines (84 loc) · 2.55 KB
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
#!/usr/bin/env ruby
require 'rubygems'
require 'open4'
require 'conditional_dcommit/package'
module ConditionalDcommit
class Command
attr_accessor :status_code
def test_command
@test_command ||= if env_command = ENV['TEST_COMMAND']
env_command
elsif(File.exists?(cruise_file=File.join(%w{script cruise})))
cruise_file
else
'rake'
end
end
def code_tests_ok?
puts "testing code"
system(test_command) ? true : false
end
def dcommit
puts "dcommitting"
system("git svn dcommit") ? true : false
end
def rebase
puts "rebasing"
pid, stdin, stdout, stderr = Open4.popen4('git svn rebase')
firstline = nil
until (firstline = stdout.gets) || (firsterror = stderr.gets)
end
puts "firstline: #{firstline}"
puts "firsterror: #{firsterror}"
matcher = /Current branch .* is up to date./
if (firsterror && firsterror.chomp =~ matcher) ||
(firstline && firstline.chomp =~ matcher)
retval = false
else
puts firstline || firsterror
while line = stdout.gets || stderr.gets
puts line
end
retval = true
end
ignored, status = Process::waitpid2 pid
raise StandardError.new("Error rebasing") if status != 0
puts "rebase return: #{retval.to_s}"
retval
end
def report_fail(message="Failed dcommit")
puts message
self.status_code = 255
growl('FAIL', message, Package.data_file('stop_sign.jpg'))
end
def report_success(message="Successful dcommit")
puts message
self.status_code = 0
growl('Success', message, Package.data_file('traffic_green.jpg'))
end
def growl(title, message, image, stick="yes")
growlNotify_file = Package.data_file('growlNotify.applescript')
system "osascript #{growlNotify_file} '#{title}' '#{message}' '#{image}' #{stick}"
end
def main
self.status_code = 254
begin
rebase
5.times do
if code_tests_ok?
unless rebase
raise StandardError.new("Error dcommitting") unless dcommit
report_success
break
end
else
raise StandardError.new("Code tests failed")
end
end && report_fail("Too many tries")
rescue StandardError => err
report_fail(err.to_s)
end
self.status_code
end
end
end