2016-09-08 09:05:00 +01:00
|
|
|
#: * `update-test` [`--commit=<sha1>`] [`--before=<date>`] [`--keep-tmp`]:
|
|
|
|
#: Runs a test of `brew update` with a new repository clone.
|
|
|
|
#:
|
|
|
|
#: If no arguments are passed, use `origin/master` as the start commit.
|
|
|
|
#:
|
|
|
|
#: If `--commit=<sha1>` is passed, use `<sha1>` as the start commit.
|
|
|
|
#:
|
|
|
|
#: If `--before=<date>` is passed, use the commit at `<date>` as the
|
|
|
|
#: start commit.
|
|
|
|
#:
|
|
|
|
#: If `--keep-tmp` is passed, retain the temporary directory containing
|
|
|
|
#: the new repository clone.
|
|
|
|
|
2015-09-06 23:08:04 +08:00
|
|
|
module Homebrew
|
|
|
|
def update_test
|
2015-09-16 15:15:04 +08:00
|
|
|
cd HOMEBREW_REPOSITORY
|
2015-12-19 18:18:56 +08:00
|
|
|
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
|
2016-08-14 11:52:22 +01:00
|
|
|
end
|
2016-08-11 11:24:03 +01:00
|
|
|
start_sha1 = Utils.popen_read("git", "rev-parse", start_sha1).chomp
|
2015-09-16 15:15:04 +08:00
|
|
|
end_sha1 = Utils.popen_read("git", "rev-parse", "HEAD").chomp
|
|
|
|
|
2015-12-19 18:18:56 +08:00
|
|
|
puts "Start commit: #{start_sha1}"
|
|
|
|
puts "End commit: #{end_sha1}"
|
|
|
|
|
2016-04-10 22:53:56 -04:00
|
|
|
mktemp("update-test") do |staging|
|
|
|
|
staging.retain! if ARGV.keep_tmp?
|
2015-09-06 23:08:04 +08:00
|
|
|
curdir = Pathname.new(Dir.pwd)
|
|
|
|
|
2015-09-14 15:19:05 +08:00
|
|
|
oh1 "Setup test environment..."
|
2015-09-06 23:08:04 +08:00
|
|
|
# copy Homebrew installation
|
2015-09-16 15:15:04 +08:00
|
|
|
safe_system "git", "clone", "--local", "#{HOMEBREW_REPOSITORY}/.git", "."
|
2015-09-14 15:19:05 +08:00
|
|
|
|
|
|
|
# set git origin to another copy
|
2015-09-16 15:15:04 +08:00
|
|
|
safe_system "git", "clone", "--local", "--bare", "#{HOMEBREW_REPOSITORY}/.git", "remote.git"
|
|
|
|
safe_system "git", "config", "remote.origin.url", "#{curdir}/remote.git"
|
2015-09-14 15:19:05 +08:00
|
|
|
|
|
|
|
# force push origin to end_sha1
|
2015-09-06 23:08:04 +08:00
|
|
|
safe_system "git", "checkout", "--force", "master"
|
2015-09-14 15:19:05 +08:00
|
|
|
safe_system "git", "reset", "--hard", end_sha1
|
|
|
|
safe_system "git", "push", "--force", "origin", "master"
|
2015-09-06 23:08:04 +08:00
|
|
|
|
2015-09-14 15:19:05 +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
|
2015-09-14 15:19:05 +08:00
|
|
|
oh1 "Running brew update..."
|
2015-09-14 08:00:50 +01:00
|
|
|
safe_system "brew", "update", "--verbose"
|
2016-08-11 11:24:03 +01:00
|
|
|
actual_end_sha1 = Utils.popen_read("git", "rev-parse", "master").chomp
|
2016-08-14 11:52:22 +01:00
|
|
|
if start_sha1 != end_sha1 && start_sha1 == actual_end_sha1
|
2016-08-11 11:24:03 +01:00
|
|
|
raise <<-EOS.undent
|
|
|
|
brew update didn't update master!
|
|
|
|
Start commit: #{start_sha1}
|
|
|
|
Expected end commit: #{end_sha1}
|
|
|
|
Actual end commit: #{actual_end_sha1}
|
|
|
|
EOS
|
|
|
|
end
|
2015-09-06 23:08:04 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|