From 992f40e119ef0117dd0f2aef445984c4684cb78a Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 1 Nov 2014 10:13:32 +0000 Subject: [PATCH] pull: pull from PR then from BrewTestBot. This allows making e.g. `Closes #X` point to the correct commit to reduce confusion and allows `--bump` to function correctly. --- Library/Homebrew/cmd/pull.rb | 77 +++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/Library/Homebrew/cmd/pull.rb b/Library/Homebrew/cmd/pull.rb index e0296060ca..e1b3892f21 100644 --- a/Library/Homebrew/cmd/pull.rb +++ b/Library/Homebrew/cmd/pull.rb @@ -10,6 +10,37 @@ module Homebrew match[1].downcase if match end + def pull_url url + # GitHub provides commits/pull-requests raw patches using this URL. + url += '.patch' + + patchpath = HOMEBREW_CACHE + File.basename(url) + curl url, '-o', patchpath + + ohai 'Applying patch' + patch_args = [] + # Normally we don't want whitespace errors, but squashing them can break + # patches so an option is provided to skip this step. + if ARGV.include? '--ignore-whitespace' or ARGV.include? '--clean' + patch_args << '--whitespace=nowarn' + else + patch_args << '--whitespace=fix' + end + + # Fall back to three-way merge if patch does not apply cleanly + patch_args << "-3" + patch_args << patchpath + + begin + safe_system 'git', 'am', *patch_args + rescue ErrorDuringExecution + system 'git', 'am', '--abort' + odie 'Patch failed to apply: aborted.' + ensure + patchpath.unlink + end + end + def pull if ARGV.empty? onoe 'This command requires at least one argument containing a URL or pull request number' @@ -34,6 +65,10 @@ module Homebrew issue = url_match[3] end + if ARGV.include?("--bottle") && issue.nil? + raise "No pull request detected!" + end + if tap_name = tap(url) user = url_match[1].downcase tap_dir = HOMEBREW_REPOSITORY/"Library/Taps/#{user}/homebrew-#{tap_name}" @@ -43,47 +78,13 @@ module Homebrew Dir.chdir HOMEBREW_REPOSITORY end - if ARGV.include? '--bottle' - if issue - url = "https://github.com/BrewTestBot/homebrew/compare/homebrew:master...pr-#{issue}" - else - raise "No pull request detected!" - end - end - - # GitHub provides commits'/pull-requests' raw patches using this URL. - url += '.patch' - # The cache directory seems like a good place to put patches. HOMEBREW_CACHE.mkpath - patchpath = HOMEBREW_CACHE + File.basename(url) - curl url, '-o', patchpath # Store current revision revision = `git rev-parse --short HEAD`.strip - ohai 'Applying patch' - patch_args = [] - # Normally we don't want whitespace errors, but squashing them can break - # patches so an option is provided to skip this step. - if ARGV.include? '--ignore-whitespace' or ARGV.include? '--clean' - patch_args << '--whitespace=nowarn' - else - patch_args << '--whitespace=fix' - end - - # Fall back to three-way merge if patch does not apply cleanly - patch_args << "-3" - patch_args << patchpath - - begin - safe_system 'git', 'am', *patch_args - rescue ErrorDuringExecution - system 'git', 'am', '--abort' - odie 'Patch failed to apply: aborted.' - ensure - patchpath.unlink - end + pull_url url changed_formulae = [] @@ -107,7 +108,7 @@ module Homebrew end end - unless ARGV.include?('--bottle') + unless ARGV.include? '--bottle' changed_formulae.each do |f| next unless f.bottle opoo "#{f.name} has a bottle: do you need to update it with --bottle?" @@ -133,6 +134,10 @@ module Homebrew end end + if ARGV.include? "--bottle" + pull_url "https://github.com/BrewTestBot/homebrew/compare/homebrew:master...pr-#{issue}" + end + ohai 'Patch changed:' safe_system "git", "diff-tree", "-r", "--stat", revision, "HEAD"