pull: add --legacy flag

It will pull legacy formula PR from Homebrew/homebrew
TODO: remove it when it's not longer necessary
This commit is contained in:
Xu Cheng 2016-03-11 22:07:15 +08:00
parent 1084b53d52
commit 360cd3cb56

View File

@ -18,6 +18,8 @@
# --resolve: When a patch fails to apply, leave in progress and allow user to # --resolve: When a patch fails to apply, leave in progress and allow user to
# resolve, instead of aborting # resolve, instead of aborting
# --branch-okay: Do not warn if pulling to a branch besides master (useful for testing) # --branch-okay: Do not warn if pulling to a branch besides master (useful for testing)
# --legacy: Pull legacy formula PR from Homebrew/homebrew
# (TODO remove it when it's not longer necessary)
require "utils" require "utils"
require "utils/json" require "utils/json"
@ -40,7 +42,11 @@ module Homebrew
ARGV.named.each do |arg| ARGV.named.each do |arg|
if arg.to_i > 0 if arg.to_i > 0
issue = arg issue = arg
if ARGV.include? "--legacy"
url = "https://github.com/Homebrew/homebrew/pull/#{arg}"
else
url = "https://github.com/Homebrew/homebrew-core/pull/#{arg}" url = "https://github.com/Homebrew/homebrew-core/pull/#{arg}"
end
tap = CoreTap.instance tap = CoreTap.instance
elsif (testing_match = arg.match %r{brew.sh/job/Homebrew.*Testing/(\d+)/}) elsif (testing_match = arg.match %r{brew.sh/job/Homebrew.*Testing/(\d+)/})
_, testing_job = *testing_match _, testing_job = *testing_match
@ -50,16 +56,20 @@ module Homebrew
elsif (api_match = arg.match HOMEBREW_PULL_API_REGEX) elsif (api_match = arg.match HOMEBREW_PULL_API_REGEX)
_, user, repo, issue = *api_match _, user, repo, issue = *api_match
url = "https://github.com/#{user}/#{repo}/pull/#{issue}" url = "https://github.com/#{user}/#{repo}/pull/#{issue}"
tap = Tap.fetch(user, repo) if repo.start_with?("homebrew-") tap = Tap.fetch(user, repo) if repo.start_with?("homebrew-") || ARGV.include?("--legacy")
elsif (url_match = arg.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX) elsif (url_match = arg.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX)
url, user, repo, issue = *url_match url, user, repo, issue = *url_match
tap = Tap.fetch(user, repo) if repo.start_with?("homebrew-") tap = Tap.fetch(user, repo) if repo.start_with?("homebrew-") || ARGV.include?("--legacy")
else else
odie "Not a GitHub pull request or commit: #{arg}" odie "Not a GitHub pull request or commit: #{arg}"
end end
if !testing_job && ARGV.include?("--bottle") && issue.nil? if !testing_job && ARGV.include?("--bottle") && issue.nil?
raise "No pull request detected!" odie "No pull request detected!"
end
if ARGV.include?("--legacy") && !tap.core_tap?
odie "--legacy can only be used for CoreTap!"
end end
if tap if tap
@ -83,6 +93,11 @@ module Homebrew
patch_puller = PatchPuller.new(url) patch_puller = PatchPuller.new(url)
patch_puller.fetch_patch patch_puller.fetch_patch
patch_changes = files_changed_in_patch(patch_puller.patchpath, tap) patch_changes = files_changed_in_patch(patch_puller.patchpath, tap)
if ARGV.include?("--legacy") && patch_changes[:others].reject { |f| f.start_with? "Library/Aliases" }.any?
odie "Cannot merge legacy PR!"
end
is_bumpable = patch_changes[:formulae].length == 1 && patch_changes[:others].empty? is_bumpable = patch_changes[:formulae].length == 1 && patch_changes[:others].empty?
if do_bump if do_bump
odie "No changed formulae found to bump" if patch_changes[:formulae].empty? odie "No changed formulae found to bump" if patch_changes[:formulae].empty?
@ -132,10 +147,13 @@ module Homebrew
orig_message = message = `git log HEAD^.. --format=%B` orig_message = message = `git log HEAD^.. --format=%B`
if issue && !ARGV.include?("--clean") if issue && !ARGV.include?("--clean")
ohai "Patch closes issue ##{issue}" ohai "Patch closes issue ##{issue}"
# If this is a pull request, append a close message. if ARGV.include?("--legacy")
unless message.include? "Closes ##{issue}." close_message = "Closes Homebrew/homebrew##{issue}."
message += "\nCloses ##{issue}." else
close_message = "Closes ##{issue}."
end end
# If this is a pull request, append a close message.
message += "\n#{close_message}" unless message.include? close_message
end end
if changed_formulae.empty? if changed_formulae.empty?
@ -280,6 +298,7 @@ module Homebrew
# Fall back to three-way merge if patch does not apply cleanly # Fall back to three-way merge if patch does not apply cleanly
patch_args << "-3" patch_args << "-3"
patch_args << "-p2" if ARGV.include?("--legacy")
patch_args << patchpath patch_args << patchpath
begin begin
@ -308,7 +327,7 @@ module Homebrew
files << $1 if line =~ %r{^\+\+\+ b/(.*)} files << $1 if line =~ %r{^\+\+\+ b/(.*)}
end end
files.each do |file| files.each do |file|
if tap && tap.formula_file?(file) if (tap && tap.formula_file?(file)) || (ARGV.include?("--legacy") && file.start_with?("Library/Formula/"))
formula_name = File.basename(file, ".rb") formula_name = File.basename(file, ".rb")
formulae << formula_name unless formulae.include?(formula_name) formulae << formula_name unless formulae.include?(formula_name)
else else