brew/Library/Homebrew/dev-cmd/update-test.rb

53 lines
1.8 KiB
Ruby
Raw Normal View History

2015-09-06 23:08:04 +08:00
module Homebrew
#
# Usage:
# brew update-test # using origin/master as start commit
# brew update-test --commit=<sha1> # using <sha1> as start commit
# brew update-test --before=<date> # using commit at <date> as start commit
#
# Options:
# --keep-tmp Retain temporary directory containing the new clone
2015-09-06 23:08:04 +08:00
def update_test
cd HOMEBREW_REPOSITORY
start_sha1 = if commit = ARGV.value("commit")
commit
elsif date = ARGV.value("before")
Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp
else
Utils.popen_read("git", "rev-parse", "origin/master").chomp
end
end_sha1 = Utils.popen_read("git", "rev-parse", "HEAD").chomp
puts "Start commit: #{start_sha1}"
puts "End commit: #{end_sha1}"
mktemp("update-test") do |staging|
staging.retain! if ARGV.keep_tmp?
2015-09-06 23:08:04 +08:00
curdir = Pathname.new(Dir.pwd)
oh1 "Setup test environment..."
2015-09-06 23:08:04 +08:00
# copy Homebrew installation
safe_system "git", "clone", "--local", "#{HOMEBREW_REPOSITORY}/.git", "."
# set git origin to another copy
safe_system "git", "clone", "--local", "--bare", "#{HOMEBREW_REPOSITORY}/.git", "remote.git"
safe_system "git", "config", "remote.origin.url", "#{curdir}/remote.git"
# force push origin to end_sha1
2015-09-06 23:08:04 +08:00
safe_system "git", "checkout", "--force", "master"
safe_system "git", "reset", "--hard", end_sha1
safe_system "git", "push", "--force", "origin", "master"
2015-09-06 23:08:04 +08:00
# set test copy to start_sha1
safe_system "git", "reset", "--hard", start_sha1
2015-09-06 23:08:04 +08:00
# update ENV["PATH"]
2016-04-02 20:07:07 +08:00
ENV["PATH"] = "#{curdir}/bin:/usr/local/bin:/usr/bin:/bin"
2015-09-06 23:08:04 +08:00
# run brew update
oh1 "Running brew update..."
2015-09-14 08:00:50 +01:00
safe_system "brew", "update", "--verbose"
2015-09-06 23:08:04 +08:00
end
end
end