| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:  * `bump-formula-pr` [`--devel`] [`--dry-run` [`--write`]] [`--audit`|`--strict`] [`--mirror=`<URL>] [`--version=`<version>] [`--message=`<message>] (`--url=`<URL> `--sha256=`<sha-256>|`--tag=`<tag> `--revision=`<revision>) <formula>: | 
					
						
							|  |  |  | #:    Creates a pull request to update the formula with a new URL or a new tag. | 
					
						
							| 
									
										
										
										
											2016-08-08 03:42:40 -04:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    If a <URL> is specified, the <sha-256> checksum of the new download must | 
					
						
							| 
									
										
										
										
											2016-09-27 03:29:47 -07:00
										 |  |  | #:    also be specified. A best effort to determine the <sha-256> and <formula> | 
					
						
							|  |  |  | #:    name will be made if either or both values are not supplied by the user. | 
					
						
							| 
									
										
										
										
											2016-08-08 03:42:40 -04:00
										 |  |  | #: | 
					
						
							|  |  |  | #:    If a <tag> is specified, the git commit <revision> corresponding to that | 
					
						
							|  |  |  | #:    tag must also be specified. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--devel` is passed, bump the development rather than stable version. | 
					
						
							|  |  |  | #:    The development spec must already exist. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--dry-run` is passed, print what would be done rather than doing it. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-09-27 03:29:47 -07:00
										 |  |  | #:    If `--write` is passed along with `--dry-run`, perform a not-so-dry run | 
					
						
							|  |  |  | #:    making the expected file modifications but not taking any git actions. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  | #:    If `--audit` is passed, run `brew audit` before opening the PR. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--strict` is passed, run `brew audit --strict` before opening the PR. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    If `--mirror=`<URL> is passed, use the value as a mirror URL. | 
					
						
							| 
									
										
										
										
											2016-09-27 03:29:47 -07:00
										 |  |  | #: | 
					
						
							|  |  |  | #:    If `--version=`<version> is passed, use the value to override the value | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    parsed from the URL or tag. Note that `--version=0` can be used to delete | 
					
						
							| 
									
										
										
										
											2016-09-27 03:29:47 -07:00
										 |  |  | #:    an existing `version` override from a formula if it has become redundant. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  | #:    If `--message=`<message> is passed, append <message> to the default PR | 
					
						
							|  |  |  | #:    message. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-10-30 09:14:53 +00:00
										 |  |  | #:    If `--no-browse` is passed, don't pass the `--browse` argument to `hub` | 
					
						
							|  |  |  | #:    which opens the pull request URL in a browser. Instead, output it to the | 
					
						
							|  |  |  | #:    command line. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-08-08 03:42:40 -04:00
										 |  |  | #:    Note that this command cannot be used to transition a formula from a | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    URL-and-sha256 style specification into a tag-and-revision style | 
					
						
							| 
									
										
										
										
											2016-08-08 03:42:40 -04:00
										 |  |  | #:    specification, nor vice versa. It must use whichever style specification | 
					
						
							|  |  |  | #:    the preexisting formula already uses. | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | require "formula" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |   def inreplace_pairs(path, replacement_pairs) | 
					
						
							|  |  |  |     if ARGV.dry_run? | 
					
						
							| 
									
										
										
										
											2016-09-24 17:59:14 +02:00
										 |  |  |       contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read } | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       contents.extend(StringInreplaceExtension) | 
					
						
							|  |  |  |       replacement_pairs.each do |old, new| | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |         unless ARGV.flag?("--quiet") | 
					
						
							|  |  |  |           ohai "replace #{old.inspect} with #{new.inspect}" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |         contents.gsub!(old, new) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-05 22:01:32 +08:00
										 |  |  |       unless contents.errors.empty? | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |         raise Utils::InreplaceError, path => contents.errors | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-09-04 11:25:00 -07:00
										 |  |  |       path.atomic_write(contents) if ARGV.include?("--write") | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       contents | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Utils::Inreplace.inreplace(path) do |s| | 
					
						
							|  |  |  |         replacement_pairs.each do |old, new| | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |           unless ARGV.flag?("--quiet") | 
					
						
							|  |  |  |             ohai "replace #{old.inspect} with #{new.inspect}" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |           s.gsub!(old, new) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-09-24 17:59:14 +02:00
										 |  |  |       path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read } | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def formula_version(formula, spec, contents = nil) | 
					
						
							|  |  |  |     name = formula.name | 
					
						
							|  |  |  |     path = formula.path | 
					
						
							|  |  |  |     if contents | 
					
						
							|  |  |  |       Formulary.from_contents(name, path, contents, spec).version | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       Formulary::FormulaLoader.new(name, path).get_formula(spec).version | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  |   def fetch_pull_requests(formula) | 
					
						
							|  |  |  |     GitHub.issues_for_formula(formula.name, tap: formula.tap).select do |pr| | 
					
						
							| 
									
										
										
										
											2017-02-18 10:16:59 -05:00
										 |  |  |       pr["html_url"].include?("/pull/") && | 
					
						
							|  |  |  |         /(^|\s)#{Regexp.quote(formula.name)}(:|\s|$)/i =~ pr["title"] | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  |     end | 
					
						
							|  |  |  |   rescue GitHub::RateLimitExceededError => e | 
					
						
							|  |  |  |     opoo e.message | 
					
						
							|  |  |  |     [] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def check_for_duplicate_pull_requests(formula) | 
					
						
							|  |  |  |     pull_requests = fetch_pull_requests(formula) | 
					
						
							| 
									
										
										
										
											2017-09-25 23:01:36 -07:00
										 |  |  |     return unless pull_requests | 
					
						
							|  |  |  |     return if pull_requests.empty? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     duplicates_message = <<~EOS | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  |       These open pull requests may be duplicates: | 
					
						
							|  |  |  |       #{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")} | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |     error_message = "Duplicate PRs should not be opened. Use --force to override this error." | 
					
						
							|  |  |  |     if ARGV.force? && !ARGV.flag?("--quiet") | 
					
						
							|  |  |  |       opoo duplicates_message | 
					
						
							|  |  |  |     elsif !ARGV.force? && ARGV.flag?("--quiet") | 
					
						
							|  |  |  |       odie error_message | 
					
						
							|  |  |  |     elsif !ARGV.force? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  |         #{duplicates_message.chomp} | 
					
						
							|  |  |  |         #{error_message} | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |   def bump_formula_pr | 
					
						
							| 
									
										
										
										
											2017-10-28 21:46:11 +01:00
										 |  |  |     # As this command is simplifying user run commands then let's just use a | 
					
						
							|  |  |  |     # user path, too. | 
					
						
							|  |  |  |     ENV["PATH"] = ENV["HOMEBREW_PATH"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-07 07:48:00 +00:00
										 |  |  |     # Use the user's browser, too. | 
					
						
							|  |  |  |     ENV["BROWSER"] = ENV["HOMEBREW_BROWSER"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-05 20:30:52 +00:00
										 |  |  |     # Setup GitHub environment variables | 
					
						
							|  |  |  |     %w[GITHUB_USER GITHUB_PASSWORD GITHUB_TOKEN].each do |env| | 
					
						
							|  |  |  |       homebrew_env = ENV["HOMEBREW_#{env}"] | 
					
						
							|  |  |  |       next unless homebrew_env | 
					
						
							|  |  |  |       next if homebrew_env.empty? | 
					
						
							|  |  |  |       ENV[env] = homebrew_env | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     formula = ARGV.formulae.first | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if formula | 
					
						
							|  |  |  |       check_for_duplicate_pull_requests(formula) | 
					
						
							|  |  |  |       checked_for_duplicates = true | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-04 11:20:03 -07:00
										 |  |  |     new_url = ARGV.value("url") | 
					
						
							|  |  |  |     if new_url && !formula | 
					
						
							|  |  |  |       is_devel = ARGV.include?("--devel") | 
					
						
							|  |  |  |       base_url = new_url.split("/")[0..4].join("/") | 
					
						
							|  |  |  |       base_url = /#{Regexp.escape(base_url)}/ | 
					
						
							|  |  |  |       guesses = [] | 
					
						
							|  |  |  |       Formula.each do |f| | 
					
						
							|  |  |  |         if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url) | 
					
						
							|  |  |  |           guesses << f | 
					
						
							| 
									
										
										
										
											2017-09-24 19:24:46 +01:00
										 |  |  |         elsif f.stable&.url && f.stable.url.match(base_url) | 
					
						
							| 
									
										
										
										
											2016-09-04 11:20:03 -07:00
										 |  |  |           guesses << f | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       if guesses.count == 1
 | 
					
						
							|  |  |  |         formula = guesses.shift | 
					
						
							|  |  |  |       elsif guesses.count > 1
 | 
					
						
							|  |  |  |         odie "Couldn't guess formula for sure: could be one of these:\n#{guesses}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     odie "No formula found!" unless formula | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-12 09:22:26 -08:00
										 |  |  |     check_for_duplicate_pull_requests(formula) unless checked_for_duplicates | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     requested_spec, formula_spec = if ARGV.include?("--devel") | 
					
						
							|  |  |  |       devel_message = " (devel)" | 
					
						
							|  |  |  |       [:devel, formula.devel] | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       [:stable, formula.stable] | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-03-28 00:29:48 +02:00
										 |  |  |     odie "#{formula}: no #{requested_spec} specification found!" unless formula_spec | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     hash_type, old_hash = if (checksum = formula_spec.checksum) | 
					
						
							|  |  |  |       [checksum.hash_type.to_s, checksum.hexdigest] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_hash = ARGV.value(hash_type) | 
					
						
							|  |  |  |     new_tag = ARGV.value("tag") | 
					
						
							|  |  |  |     new_revision = ARGV.value("revision") | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:02 -07:00
										 |  |  |     new_mirror = ARGV.value("mirror") | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     forced_version = ARGV.value("version") | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     new_url_hash = if new_url && new_hash | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     elsif new_tag && new_revision | 
					
						
							|  |  |  |       false | 
					
						
							|  |  |  |     elsif !hash_type | 
					
						
							| 
									
										
										
										
											2017-12-11 09:02:41 +00:00
										 |  |  |       odie "#{formula}: no --tag=/--revision= arguments specified!" | 
					
						
							| 
									
										
										
										
											2017-01-09 12:16:55 +00:00
										 |  |  |     elsif !new_url | 
					
						
							| 
									
										
										
										
											2017-12-11 09:02:41 +00:00
										 |  |  |       odie "#{formula}: no --url= argument specified!" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2016-09-04 11:21:08 -07:00
										 |  |  |       rsrc_url = if requested_spec != :devel && new_url =~ /.*ftpmirror.gnu.*/ | 
					
						
							|  |  |  |         new_mirror = new_url.sub "ftpmirror.gnu.org", "ftp.gnu.org/gnu" | 
					
						
							|  |  |  |         new_mirror | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         new_url | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       rsrc = Resource.new { @url = rsrc_url } | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:38 -07:00
										 |  |  |       rsrc.download_strategy = CurlDownloadStrategy | 
					
						
							|  |  |  |       rsrc.owner = Resource.new(formula.name) | 
					
						
							| 
									
										
										
										
											2016-12-06 17:30:10 -05:00
										 |  |  |       rsrc.version = forced_version if forced_version | 
					
						
							| 
									
										
										
										
											2017-12-11 09:02:41 +00:00
										 |  |  |       odie "No --version= argument specified!" unless rsrc.version | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:38 -07:00
										 |  |  |       rsrc_path = rsrc.fetch | 
					
						
							| 
									
										
										
										
											2017-08-07 18:57:55 -07:00
										 |  |  |       gnu_tar_gtar_path = HOMEBREW_PREFIX/"opt/gnu-tar/bin/gtar" | 
					
						
							|  |  |  |       gnu_tar_gtar = gnu_tar_gtar_path if gnu_tar_gtar_path.executable? | 
					
						
							|  |  |  |       tar = which("gtar") || gnu_tar_gtar || which("tar") | 
					
						
							|  |  |  |       if Utils.popen_read(tar, "-tf", rsrc_path) =~ %r{/.*\.} | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:38 -07:00
										 |  |  |         new_hash = rsrc_path.sha256 | 
					
						
							| 
									
										
										
										
											2016-09-27 03:30:40 -07:00
										 |  |  |       elsif new_url.include? ".tar" | 
					
						
							| 
									
										
										
										
											2017-12-11 09:02:41 +00:00
										 |  |  |         odie "#{formula}: no --url=/--#{hash_type}= arguments specified!" | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:38 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ARGV.dry_run? | 
					
						
							|  |  |  |       ohai "brew update" | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       safe_system "brew", "update" | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |     old_formula_version = formula_version(formula, requested_spec) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |     replacement_pairs = [] | 
					
						
							| 
									
										
										
										
											2016-09-11 17:41:51 +01:00
										 |  |  |     if requested_spec == :stable && formula.revision.nonzero? | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |       replacement_pairs << [/^  revision \d+\n(\n(  head "))?/m, "\\2"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-22 00:54:08 -05:00
										 |  |  |     replacement_pairs += formula_spec.mirrors.map do |mirror| | 
					
						
							|  |  |  |       [/ +mirror \"#{mirror}\"\n/m, ""] | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 08:17:56 -07:00
										 |  |  |     replacement_pairs += if new_url_hash | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |       [ | 
					
						
							|  |  |  |         [formula_spec.url, new_url], | 
					
						
							|  |  |  |         [old_hash, new_hash], | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       [ | 
					
						
							|  |  |  |         [formula_spec.specs[:tag], new_tag], | 
					
						
							|  |  |  |         [formula_spec.specs[:revision], new_revision], | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  |     backup_file = File.read(formula.path) unless ARGV.dry_run? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-04 11:28:02 -07:00
										 |  |  |     if new_mirror | 
					
						
							|  |  |  |       replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1mirror \"#{new_mirror}\"\n"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     if forced_version && forced_version != "0" | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       if requested_spec == :stable | 
					
						
							|  |  |  |         if File.read(formula.path).include?("version \"#{old_formula_version}\"") | 
					
						
							|  |  |  |           replacement_pairs << [old_formula_version.to_s, forced_version] | 
					
						
							| 
									
										
										
										
											2016-09-27 03:30:40 -07:00
										 |  |  |         elsif new_mirror | 
					
						
							|  |  |  |           replacement_pairs << [/^( +)(mirror \"#{new_mirror}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] | 
					
						
							| 
									
										
										
										
											2016-09-04 11:21:08 -07:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2016-09-27 03:30:40 -07:00
										 |  |  |           replacement_pairs << [/^( +)(url \"#{new_url}\"\n)/m, "\\1\\2\\1version \"#{forced_version}\"\n"] | 
					
						
							| 
									
										
										
										
											2016-09-04 11:21:08 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       elsif requested_spec == :devel | 
					
						
							|  |  |  |         replacement_pairs << [/(  devel do.+?version \")#{old_formula_version}(\"\n.+?end\n)/m, "\\1#{forced_version}\\2"] | 
					
						
							| 
									
										
										
										
											2016-09-04 11:21:08 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     elsif forced_version && forced_version == "0" | 
					
						
							| 
									
										
										
										
											2016-09-27 02:50:46 -07:00
										 |  |  |       if requested_spec == :stable | 
					
						
							|  |  |  |         replacement_pairs << [/^  version \"[a-z\d+\.]+\"\n/m, ""] | 
					
						
							|  |  |  |       elsif requested_spec == :devel | 
					
						
							|  |  |  |         replacement_pairs << [/(  devel do.+?)^ +version \"[^\n]+\"\n(.+?end\n)/m, "\\1\\2"] | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-07-06 05:00:45 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |     new_contents = inreplace_pairs(formula.path, replacement_pairs) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     new_formula_version = formula_version(formula, requested_spec, new_contents) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if new_formula_version < old_formula_version | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  |       formula.path.atomic_write(backup_file) unless ARGV.dry_run? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |         You probably need to bump this formula manually since changing the | 
					
						
							|  |  |  |         version from #{old_formula_version} to #{new_formula_version} would be a downgrade. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     elsif new_formula_version == old_formula_version | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  |       formula.path.atomic_write(backup_file) unless ARGV.dry_run? | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |       odie <<~EOS | 
					
						
							| 
									
										
										
										
											2016-06-16 14:25:53 -07:00
										 |  |  |         You probably need to bump this formula manually since the new version | 
					
						
							|  |  |  |         and old version are both #{new_formula_version}. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  |     if ARGV.dry_run? | 
					
						
							|  |  |  |       if ARGV.include? "--strict" | 
					
						
							|  |  |  |         ohai "brew audit --strict #{formula.path.basename}" | 
					
						
							|  |  |  |       elsif ARGV.include? "--audit" | 
					
						
							|  |  |  |         ohai "brew audit #{formula.path.basename}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       failed_audit = false | 
					
						
							|  |  |  |       if ARGV.include? "--strict" | 
					
						
							|  |  |  |         system HOMEBREW_BREW_FILE, "audit", "--strict", formula.path | 
					
						
							| 
									
										
										
										
											2017-06-10 20:12:55 +03:00
										 |  |  |         failed_audit = !$CHILD_STATUS.success? | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  |       elsif ARGV.include? "--audit" | 
					
						
							|  |  |  |         system HOMEBREW_BREW_FILE, "audit", formula.path | 
					
						
							| 
									
										
										
										
											2017-06-10 20:12:55 +03:00
										 |  |  |         failed_audit = !$CHILD_STATUS.success? | 
					
						
							| 
									
										
										
										
											2016-06-17 10:10:47 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |       if failed_audit | 
					
						
							|  |  |  |         formula.path.atomic_write(backup_file) | 
					
						
							|  |  |  |         odie "brew audit failed!" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |     unless Formula["hub"].any_version_installed? | 
					
						
							|  |  |  |       if ARGV.dry_run? | 
					
						
							|  |  |  |         ohai "brew install hub" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         safe_system "brew", "install", "hub" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     formula.path.parent.cd do | 
					
						
							|  |  |  |       branch = "#{formula.name}-#{new_formula_version}" | 
					
						
							| 
									
										
										
										
											2017-06-29 13:28:55 +02:00
										 |  |  |       git_dir = Utils.popen_read("git rev-parse --git-dir").chomp | 
					
						
							| 
									
										
										
										
											2017-06-27 23:45:57 +02:00
										 |  |  |       shallow = !git_dir.empty? && File.exist?("#{git_dir}/shallow") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-30 09:14:53 +00:00
										 |  |  |       hub_args = [] | 
					
						
							|  |  |  |       git_final_checkout_args = [] | 
					
						
							|  |  |  |       if ARGV.include?("--no-browse") | 
					
						
							|  |  |  |         git_final_checkout_args << "--quiet" | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         hub_args << "--browse" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       if ARGV.dry_run? | 
					
						
							| 
									
										
										
										
											2017-11-21 08:16:12 -08:00
										 |  |  |         ohai "hub fork # read $HUB_REMOTE" | 
					
						
							| 
									
										
										
										
											2017-06-27 23:45:57 +02:00
										 |  |  |         ohai "git fetch --unshallow origin" if shallow | 
					
						
							| 
									
										
										
										
											2016-08-19 10:32:54 -04:00
										 |  |  |         ohai "git checkout --no-track -b #{branch} origin/master" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |         ohai "git commit --no-edit --verbose --message='#{formula.name} #{new_formula_version}#{devel_message}' -- #{formula.path}" | 
					
						
							| 
									
										
										
										
											2016-08-19 10:32:54 -04:00
										 |  |  |         ohai "git push --set-upstream $HUB_REMOTE #{branch}:#{branch}" | 
					
						
							| 
									
										
										
										
											2017-10-30 09:14:53 +00:00
										 |  |  |         ohai "hub pull-request #{hub_args.join(" ")} -m '#{formula.name} #{new_formula_version}#{devel_message}'" | 
					
						
							| 
									
										
										
										
											2016-08-19 15:59:55 -04:00
										 |  |  |         ohai "git checkout -" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       else | 
					
						
							| 
									
										
										
										
											2017-11-21 08:16:12 -08:00
										 |  |  |         reply = IO.popen(["hub", "fork"], "r+", err: "/dev/null") do |io| | 
					
						
							|  |  |  |           reader = Thread.new { io.read } | 
					
						
							|  |  |  |           sleep 1
 | 
					
						
							|  |  |  |           io.close_write | 
					
						
							|  |  |  |           reader.value | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if reply.to_s.include? "username:" | 
					
						
							|  |  |  |           formula.path.atomic_write(backup_file) unless ARGV.dry_run? | 
					
						
							| 
									
										
										
										
											2017-12-11 09:02:41 +00:00
										 |  |  |           git_path = "$(brew --repo #{formula.tap})" if formula.tap | 
					
						
							|  |  |  |           git_path ||= formula.path.parent | 
					
						
							|  |  |  |           odie <<~EOS | 
					
						
							|  |  |  |             Retry after configuring hub by running: | 
					
						
							|  |  |  |               hub -C "#{git_path}" fork | 
					
						
							|  |  |  |             Or setting HOMEBREW_GITHUB_TOKEN with at least 'public_repo' scope. | 
					
						
							|  |  |  |           EOS | 
					
						
							| 
									
										
										
										
											2017-11-21 08:16:12 -08:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         remote = reply[/remote:? (\S+)/, 1] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # repeat for hub 2.2 backwards compatibility: | 
					
						
							| 
									
										
										
										
											2017-12-14 15:06:52 +00:00
										 |  |  |         remote = Utils.popen_read("hub", "fork", err: :out)[/remote:? (\S+)/, 1] if remote.to_s.empty? | 
					
						
							| 
									
										
										
										
											2017-11-21 08:16:12 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if remote.to_s.empty? | 
					
						
							|  |  |  |           formula.path.atomic_write(backup_file) unless ARGV.dry_run? | 
					
						
							|  |  |  |           odie "cannot get remote from 'hub'!" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-27 23:45:57 +02:00
										 |  |  |         safe_system "git", "fetch", "--unshallow", "origin" if shallow | 
					
						
							| 
									
										
										
										
											2016-08-19 10:32:54 -04:00
										 |  |  |         safe_system "git", "checkout", "--no-track", "-b", branch, "origin/master" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |         safe_system "git", "commit", "--no-edit", "--verbose", | 
					
						
							|  |  |  |           "--message=#{formula.name} #{new_formula_version}#{devel_message}", | 
					
						
							|  |  |  |           "--", formula.path | 
					
						
							| 
									
										
										
										
											2016-08-19 10:32:54 -04:00
										 |  |  |         safe_system "git", "push", "--set-upstream", remote, "#{branch}:#{branch}" | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |         pr_message = <<~EOS | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  |           #{formula.name} #{new_formula_version}#{devel_message} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           Created with `brew bump-formula-pr`. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |         user_message = ARGV.value("message") | 
					
						
							|  |  |  |         if user_message | 
					
						
							| 
									
										
										
										
											2017-10-31 14:16:09 -04:00
										 |  |  |           pr_message += "\n" + <<~EOS | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  |             --- | 
					
						
							| 
									
										
										
										
											2017-10-31 14:16:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-15 11:37:49 -05:00
										 |  |  |             #{user_message} | 
					
						
							|  |  |  |           EOS | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-30 09:14:53 +00:00
										 |  |  |         safe_system "hub", "pull-request", *hub_args, "-m", pr_message | 
					
						
							|  |  |  |         safe_system "git", "checkout", *git_final_checkout_args, "-" | 
					
						
							| 
									
										
										
										
											2016-03-17 05:58:14 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |