brew-test-bot: Change directory only for Git commands.

This commit is contained in:
Mike McQuaid 2012-11-10 09:05:31 +00:00
parent d01adbc987
commit 25442f20ec

View File

@ -70,7 +70,14 @@ class Step
def self.run test, command, output_on_success = false def self.run test, command, output_on_success = false
step = new test, command step = new test, command
step.puts_command step.puts_command
`#{step.command} &>#{step.log_file_path}`
command = "#{step.command} &>#{step.log_file_path}"
if command.start_with? 'git '
Dir.chdir HOMEBREW_REPOSITORY { `#{command}` }
else
`#{command}`
end
step.status = $?.success? ? :passed : :failed step.status = $?.success? ? :passed : :failed
step.puts_result step.puts_result
puts IO.read(step.log_file_path) if output_on_success puts IO.read(step.log_file_path) if output_on_success
@ -142,18 +149,24 @@ class Test
end end
end end
def git arguments
Dir.chdir HOMEBREW_REPOSITORY do
`git #{arguments}`
end
end
def download def download
def current_sha1 def current_sha1
`git rev-parse --short HEAD`.strip git('rev-parse --short HEAD').strip
end end
def current_branch def current_branch
`git symbolic-ref HEAD`.slice!("refs/heads/").strip git('symbolic-ref HEAD').slice!("refs/heads/").strip
end end
@category = __method__ @category = __method__
if @url if @url
`git am --abort 2>/dev/null` git 'am --abort 2>/dev/null'
test "brew update" if current_branch == "master" test "brew update" if current_branch == "master"
@start_sha1 = current_sha1 @start_sha1 = current_sha1
test "brew pull --clean #{@url}" test "brew pull --clean #{@url}"
@ -171,7 +184,7 @@ class Test
return unless @url and @start_sha1 != end_sha1 and steps.last.status == :passed return unless @url and @start_sha1 != end_sha1 and steps.last.status == :passed
`git diff #{@start_sha1}..#{end_sha1} --name-status`.each_line do |line| git("diff #{@start_sha1}..#{end_sha1} --name-status`.each_line") do |line|
status, filename = line.split status, filename = line.split
# Don't try and do anything to removed files. # Don't try and do anything to removed files.
if (status == 'A' or status == 'M') if (status == 'A' or status == 'M')
@ -216,7 +229,7 @@ class Test
test "git reset --hard origin/master" test "git reset --hard origin/master"
test "git clean --force -dx" test "git clean --force -dx"
else else
`git diff --exit-code HEAD 2>/dev/null` git('diff --exit-code HEAD 2>/dev/null')
odie "Uncommitted changes, aborting." unless $?.success? odie "Uncommitted changes, aborting." unless $?.success?
test "git reset --hard #{@start_sha1}" if @start_sha1 test "git reset --hard #{@start_sha1}" if @start_sha1
end end
@ -273,8 +286,6 @@ if ARGV.empty?
odie 'This command requires at least one argument containing a pull request number or formula.' odie 'This command requires at least one argument containing a pull request number or formula.'
end end
Dir.chdir HOMEBREW_REPOSITORY
ARGV.named.each do|arg| ARGV.named.each do|arg|
Test.run arg Test.run arg
end end