2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-04-17 18:25:08 +09:00
|
|
|
require "cli/parser"
|
2018-03-25 21:39:02 +05:30
|
|
|
|
2015-09-06 23:08:04 +08:00
|
|
|
module Homebrew
|
2016-09-26 01:44:51 +02:00
|
|
|
module_function
|
|
|
|
|
2018-07-30 18:25:38 +05:30
|
|
|
def update_test_args
|
|
|
|
Homebrew::CLI::Parser.new do
|
2018-09-28 21:39:52 +05:30
|
|
|
usage_banner <<~EOS
|
2018-10-15 15:06:33 -04:00
|
|
|
`update-test` [<options>]
|
2018-09-28 21:39:52 +05:30
|
|
|
|
2018-10-08 22:49:03 -04:00
|
|
|
Run a test of `brew update` with a new repository clone.
|
2019-08-19 22:44:50 -04:00
|
|
|
If no options are passed, use `origin/master` as the start commit.
|
2018-09-28 21:39:52 +05:30
|
|
|
EOS
|
|
|
|
switch "--to-tag",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Set `HOMEBREW_UPDATE_TO_TAG` to test updating between tags."
|
2018-09-28 21:39:52 +05:30
|
|
|
switch "--keep-tmp",
|
2019-04-30 08:44:35 +01:00
|
|
|
description: "Retain the temporary directory containing the new repository clone."
|
2018-09-28 21:39:52 +05:30
|
|
|
flag "--commit=",
|
2019-08-20 00:04:14 -04:00
|
|
|
description: "Use the specified <commit> as the start commit."
|
2018-09-28 21:39:52 +05:30
|
|
|
flag "--before=",
|
2019-08-20 00:04:14 -04:00
|
|
|
description: "Use the commit at the specified <date> as the start commit."
|
2018-04-01 16:47:30 +05:30
|
|
|
switch :verbose
|
|
|
|
switch :debug
|
2019-12-13 16:50:54 -05:00
|
|
|
max_named 0
|
2018-03-25 21:39:02 +05:30
|
|
|
end
|
2018-07-30 18:25:38 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def update_test
|
|
|
|
update_test_args.parse
|
2018-03-25 21:39:02 +05:30
|
|
|
|
2016-10-02 17:16:35 +01:00
|
|
|
ENV["HOMEBREW_UPDATE_TEST"] = "1"
|
|
|
|
|
2018-07-03 15:41:33 +01:00
|
|
|
branch = if args.to_tag?
|
2016-10-02 17:16:35 +01:00
|
|
|
ENV["HOMEBREW_UPDATE_TO_TAG"] = "1"
|
2018-07-03 15:41:33 +01:00
|
|
|
"stable"
|
2016-10-02 17:16:35 +01:00
|
|
|
else
|
2018-07-03 15:41:33 +01:00
|
|
|
"master"
|
2016-10-02 17:16:35 +01:00
|
|
|
end
|
2016-10-01 13:29:18 +01:00
|
|
|
|
2018-07-03 15:41:33 +01:00
|
|
|
start_commit, end_commit = nil
|
|
|
|
cd HOMEBREW_REPOSITORY do
|
|
|
|
start_commit = if commit = args.commit
|
|
|
|
commit
|
|
|
|
elsif date = args.before
|
|
|
|
Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp
|
|
|
|
elsif args.to_tag?
|
|
|
|
tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname")
|
2019-08-19 13:49:32 +01:00
|
|
|
if tags.blank?
|
|
|
|
tags = if (HOMEBREW_REPOSITORY/".git/shallow").exist?
|
2018-07-03 15:41:33 +01:00
|
|
|
safe_system "git", "fetch", "--tags", "--depth=1"
|
2019-08-19 13:49:32 +01:00
|
|
|
Utils.popen_read("git", "tag", "--list", "--sort=-version:refname")
|
2018-07-03 15:41:33 +01:00
|
|
|
elsif OS.linux?
|
2019-08-19 13:49:32 +01:00
|
|
|
Utils.popen_read("git tag --list | sort -rV")
|
2018-07-03 15:41:33 +01:00
|
|
|
end
|
2017-05-29 15:13:08 +01:00
|
|
|
end
|
2019-08-19 13:49:32 +01:00
|
|
|
current_tag, previous_tag, = tags.lines
|
|
|
|
current_tag = current_tag.to_s.chomp
|
|
|
|
odie "Could not find current tag in:\n#{tags}" if current_tag.empty?
|
|
|
|
# ^0 ensures this points to the commit rather than the tag object.
|
|
|
|
end_commit = "#{current_tag}^0"
|
|
|
|
|
2018-07-03 15:41:33 +01:00
|
|
|
previous_tag = previous_tag.to_s.chomp
|
|
|
|
odie "Could not find previous tag in:\n#{tags}" if previous_tag.empty?
|
2019-08-19 13:49:32 +01:00
|
|
|
# ^0 ensures this points to the commit rather than the tag object.
|
|
|
|
"#{previous_tag}^0"
|
2018-07-03 15:41:33 +01:00
|
|
|
else
|
|
|
|
Utils.popen_read("git", "rev-parse", "origin/master").chomp
|
2017-03-28 15:31:16 +01:00
|
|
|
end
|
2018-07-03 15:41:33 +01:00
|
|
|
odie "Could not find start commit!" if start_commit.empty?
|
2017-03-28 15:31:16 +01:00
|
|
|
|
2018-07-03 15:41:33 +01:00
|
|
|
start_commit = Utils.popen_read("git", "rev-parse", start_commit).chomp
|
|
|
|
odie "Could not find start commit!" if start_commit.empty?
|
2017-03-28 15:31:16 +01:00
|
|
|
|
2019-08-19 13:49:32 +01:00
|
|
|
end_commit ||= "HEAD"
|
|
|
|
end_commit = Utils.popen_read("git", "rev-parse", end_commit).chomp
|
2018-07-03 15:41:33 +01:00
|
|
|
odie "Could not find end commit!" if end_commit.empty?
|
2019-08-19 13:49:32 +01:00
|
|
|
|
|
|
|
if Utils.popen_read("git", "branch", "--list", "master").blank?
|
|
|
|
safe_system "git", "branch", "master", "origin/master"
|
|
|
|
end
|
2018-07-03 15:41:33 +01:00
|
|
|
end
|
2015-09-16 15:15:04 +08:00
|
|
|
|
2016-09-22 19:26:41 +01:00
|
|
|
puts "Start commit: #{start_commit}"
|
2019-04-01 16:02:13 -04:00
|
|
|
puts " End commit: #{end_commit}"
|
2015-12-19 18:18:56 +08:00
|
|
|
|
2018-12-27 12:01:47 -08:00
|
|
|
mkdir "update-test"
|
|
|
|
chdir "update-test" do
|
2015-09-06 23:08:04 +08:00
|
|
|
curdir = Pathname.new(Dir.pwd)
|
|
|
|
|
2019-12-13 15:39:55 -05:00
|
|
|
oh1 "Preparing test environment..."
|
2015-09-06 23:08:04 +08:00
|
|
|
# copy Homebrew installation
|
2019-08-19 13:49:32 +01:00
|
|
|
safe_system "git", "clone", "#{HOMEBREW_REPOSITORY}/.git", ".",
|
2019-11-16 09:39:18 +00:00
|
|
|
"--branch", "master", "--single-branch"
|
2015-09-14 15:19:05 +08:00
|
|
|
|
|
|
|
# set git origin to another copy
|
2019-08-19 13:49:32 +01:00
|
|
|
safe_system "git", "clone", "#{HOMEBREW_REPOSITORY}/.git", "remote.git",
|
2019-11-16 09:39:18 +00:00
|
|
|
"--bare", "--branch", "master", "--single-branch"
|
2015-09-16 15:15:04 +08:00
|
|
|
safe_system "git", "config", "remote.origin.url", "#{curdir}/remote.git"
|
2015-09-14 15:19:05 +08:00
|
|
|
|
2016-09-22 19:26:41 +01:00
|
|
|
# force push origin to end_commit
|
|
|
|
safe_system "git", "checkout", "-B", "master", end_commit
|
2015-09-14 15:19:05 +08:00
|
|
|
safe_system "git", "push", "--force", "origin", "master"
|
2015-09-06 23:08:04 +08:00
|
|
|
|
2016-09-22 19:26:41 +01:00
|
|
|
# set test copy to start_commit
|
|
|
|
safe_system "git", "reset", "--hard", start_commit
|
2015-09-06 23:08:04 +08:00
|
|
|
|
|
|
|
# update ENV["PATH"]
|
2017-09-29 22:10:44 +02:00
|
|
|
ENV["PATH"] = PATH.new(ENV["PATH"]).prepend(curdir/"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-10-02 17:16:35 +01:00
|
|
|
actual_end_commit = Utils.popen_read("git", "rev-parse", branch).chomp
|
2019-08-19 13:49:32 +01:00
|
|
|
if actual_end_commit != end_commit
|
2017-10-15 02:28:32 +02:00
|
|
|
raise <<~EOS
|
2016-10-02 17:16:35 +01:00
|
|
|
brew update didn't update #{branch}!
|
2016-09-22 19:26:41 +01:00
|
|
|
Start commit: #{start_commit}
|
|
|
|
Expected end commit: #{end_commit}
|
|
|
|
Actual end commit: #{actual_end_commit}
|
2016-08-11 11:24:03 +01:00
|
|
|
EOS
|
|
|
|
end
|
2015-09-06 23:08:04 +08:00
|
|
|
end
|
2018-07-03 15:41:33 +01:00
|
|
|
ensure
|
2020-07-23 02:58:12 +02:00
|
|
|
FileUtils.rm_rf "update-test" unless args.keep_tmp?
|
2015-09-06 23:08:04 +08:00
|
|
|
end
|
|
|
|
end
|