brew-test-bot: make git commands shell-safe
This commit is contained in:
parent
299b272c6c
commit
4e29bab683
@ -127,7 +127,7 @@ class Test
|
|||||||
|
|
||||||
url_match = argument.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX
|
url_match = argument.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX
|
||||||
formula = Formula.factory argument rescue FormulaUnavailableError
|
formula = Formula.factory argument rescue FormulaUnavailableError
|
||||||
git "rev-parse --verify #{argument} &>/dev/null"
|
git "rev-parse", "--verify", "-q", argument
|
||||||
if $?.success?
|
if $?.success?
|
||||||
@hash = argument
|
@hash = argument
|
||||||
elsif url_match
|
elsif url_match
|
||||||
@ -148,15 +148,27 @@ class Test
|
|||||||
@hash == 'HEAD'
|
@hash == 'HEAD'
|
||||||
end
|
end
|
||||||
|
|
||||||
def git arguments
|
def git(*args)
|
||||||
Dir.chdir HOMEBREW_REPOSITORY do
|
rd, wr = IO.pipe
|
||||||
`git #{arguments}`
|
|
||||||
|
pid = fork do
|
||||||
|
rd.close
|
||||||
|
STDERR.reopen("/dev/null")
|
||||||
|
STDOUT.reopen(wr)
|
||||||
|
Dir.chdir HOMEBREW_REPOSITORY
|
||||||
|
exec("git", *args)
|
||||||
end
|
end
|
||||||
|
wr.close
|
||||||
|
Process.wait(pid)
|
||||||
|
|
||||||
|
rd.read
|
||||||
|
ensure
|
||||||
|
rd.close
|
||||||
end
|
end
|
||||||
|
|
||||||
def download
|
def download
|
||||||
def shorten_revision revision
|
def shorten_revision revision
|
||||||
git("rev-parse --short #{revision}").strip
|
git("rev-parse", "--short", revision).strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def current_sha1
|
def current_sha1
|
||||||
@ -164,11 +176,11 @@ class Test
|
|||||||
end
|
end
|
||||||
|
|
||||||
def current_branch
|
def current_branch
|
||||||
git('symbolic-ref HEAD').gsub('refs/heads/', '').strip
|
git("symbolic-ref", "HEAD").gsub("refs/heads/", "").strip
|
||||||
end
|
end
|
||||||
|
|
||||||
def single_commit? start_revision, end_revision
|
def single_commit? start_revision, end_revision
|
||||||
git("rev-list --count #{start_revision}..#{end_revision}").to_i == 1
|
git("rev-list", "--count", "#{start_revision}..#{end_revision}").to_i == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
@category = __method__
|
@category = __method__
|
||||||
@ -235,7 +247,7 @@ class Test
|
|||||||
return unless diff_start_sha1 != diff_end_sha1
|
return unless diff_start_sha1 != diff_end_sha1
|
||||||
return if @url and not steps.last.passed?
|
return if @url and not steps.last.passed?
|
||||||
|
|
||||||
diff_stat = git "diff #{diff_start_sha1}..#{diff_end_sha1} --name-status"
|
diff_stat = git "diff", "#{diff_start_sha1}..#{diff_end_sha1}", "--name-status"
|
||||||
diff_stat.each_line do |line|
|
diff_stat.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.
|
||||||
@ -357,12 +369,12 @@ class Test
|
|||||||
def cleanup_before
|
def cleanup_before
|
||||||
@category = __method__
|
@category = __method__
|
||||||
return unless ARGV.include? '--cleanup'
|
return unless ARGV.include? '--cleanup'
|
||||||
git 'stash'
|
git "stash"
|
||||||
git 'am --abort 2>/dev/null'
|
git "am", "--abort"
|
||||||
git 'rebase --abort 2>/dev/null'
|
git "rebase", "--abort"
|
||||||
git 'reset --hard'
|
git "reset", "--hard"
|
||||||
git 'checkout -f master 2>/dev/null'
|
git "checkout", "-f", "master"
|
||||||
git 'clean --force -dx'
|
git "clean", "--force", "-dx"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup_after
|
def cleanup_after
|
||||||
@ -381,7 +393,7 @@ class Test
|
|||||||
|
|
||||||
if ARGV.include? '--cleanup'
|
if ARGV.include? '--cleanup'
|
||||||
test "git", "reset", "--hard"
|
test "git", "reset", "--hard"
|
||||||
git 'stash pop 2>/dev/null'
|
git "stash", "pop"
|
||||||
test "brew", "cleanup"
|
test "brew", "cleanup"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user