| 
									
										
										
										
											2017-03-05 21:45:15 -05:00
										 |  |  | #:  * `update-test` [`--commit=`<commit>] [`--before=`<date>] [`--to-tag`] [`--keep-tmp`]: | 
					
						
							| 
									
										
										
										
											2016-09-08 09:05:00 +01:00
										 |  |  | #:    Runs a test of `brew update` with a new repository clone. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If no arguments are passed, use `origin/master` as the start commit. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    If `--commit=`<commit> is passed, use <commit> as the start commit. | 
					
						
							| 
									
										
										
										
											2016-09-08 09:05:00 +01:00
										 |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    If `--before=`<date> is passed, use the commit at <date> as the | 
					
						
							| 
									
										
										
										
											2016-09-08 09:05:00 +01:00
										 |  |  | #:    start commit. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2017-02-25 17:37:57 -05:00
										 |  |  | #:    If `--to-tag` is passed, set `HOMEBREW_UPDATE_TO_TAG` to test updating | 
					
						
							| 
									
										
										
										
											2016-10-01 13:29:18 +01:00
										 |  |  | #:    between tags. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-09-08 09:05:00 +01:00
										 |  |  | #:    If `--keep-tmp` is passed, retain the temporary directory containing | 
					
						
							|  |  |  | #:    the new repository clone. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 21:39:02 +05:30
										 |  |  | require "cli_parser" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 23:08:04 +08:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-06 23:08:04 +08:00
										 |  |  |   def update_test | 
					
						
							| 
									
										
										
										
											2018-05-05 18:40:01 +05:30
										 |  |  |     Homebrew::CLI::Parser.parse do | 
					
						
							| 
									
										
										
										
											2018-03-25 21:39:02 +05:30
										 |  |  |       switch "--to-tag" | 
					
						
							|  |  |  |       switch "--keep-tmp" | 
					
						
							| 
									
										
										
										
											2018-04-01 16:47:30 +05:30
										 |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							| 
									
										
										
										
											2018-04-14 19:04:24 +05:30
										 |  |  |       flag   "--commit=" | 
					
						
							|  |  |  |       flag   "--before=" | 
					
						
							| 
									
										
										
										
											2018-03-25 21:39:02 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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") | 
					
						
							|  |  |  |         previous_tag = tags.lines[1] | 
					
						
							|  |  |  |         previous_tag ||= begin | 
					
						
							|  |  |  |           if (HOMEBREW_REPOSITORY/".git/shallow").exist? | 
					
						
							|  |  |  |             safe_system "git", "fetch", "--tags", "--depth=1" | 
					
						
							|  |  |  |             tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") | 
					
						
							|  |  |  |           elsif OS.linux? | 
					
						
							|  |  |  |             tags = Utils.popen_read("git tag --list | sort -rV") | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           tags.lines[1] | 
					
						
							| 
									
										
										
										
											2017-05-29 15:13:08 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											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? | 
					
						
							|  |  |  |         previous_tag | 
					
						
							|  |  |  |       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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 15:41:33 +01:00
										 |  |  |       end_commit = Utils.popen_read("git", "rev-parse", "HEAD").chomp | 
					
						
							|  |  |  |       odie "Could not find end commit!" if end_commit.empty? | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-09-16 15:15:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-22 19:26:41 +01:00
										 |  |  |     puts "Start commit: #{start_commit}" | 
					
						
							|  |  |  |     puts "End   commit: #{end_commit}" | 
					
						
							| 
									
										
										
										
											2015-12-19 18:18:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-03 15:41:33 +01:00
										 |  |  |     mkdir "update-test" do | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2016-09-22 19:26:41 +01:00
										 |  |  |       if start_commit != end_commit && start_commit == actual_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 | 
					
						
							|  |  |  |     FileUtils.rm_r "update-test" unless args.keep_tmp? | 
					
						
							| 
									
										
										
										
											2015-09-06 23:08:04 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | end |