| 
									
										
										
										
											2024-06-02 15:14:25 +01:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  | require "abstract_command" | 
					
						
							|  |  |  | require "fileutils" | 
					
						
							| 
									
										
										
										
											2015-05-08 13:48:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |   module Cmd | 
					
						
							|  |  |  |     class Log < AbstractCommand | 
					
						
							|  |  |  |       include FileUtils | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |       cmd_args do | 
					
						
							|  |  |  |         description <<~EOS | 
					
						
							|  |  |  |           Show the `git log` for <formula> or <cask>, or show the log for the Homebrew repository | 
					
						
							|  |  |  |           if no formula or cask is provided. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |         switch "-p", "-u", "--patch", | 
					
						
							|  |  |  |                description: "Also print patch from commit." | 
					
						
							|  |  |  |         switch "--stat", | 
					
						
							|  |  |  |                description: "Also print diffstat from commit." | 
					
						
							|  |  |  |         switch "--oneline", | 
					
						
							|  |  |  |                description: "Print only one line per commit." | 
					
						
							|  |  |  |         switch "-1", | 
					
						
							|  |  |  |                description: "Print only one commit." | 
					
						
							|  |  |  |         flag   "-n", "--max-count=", | 
					
						
							|  |  |  |                description: "Print only a specified number of commits." | 
					
						
							|  |  |  |         switch "--formula", "--formulae", | 
					
						
							|  |  |  |                description: "Treat all named arguments as formulae." | 
					
						
							|  |  |  |         switch "--cask", "--casks", | 
					
						
							|  |  |  |                description: "Treat all named arguments as casks." | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |         conflicts "-1", "--max-count" | 
					
						
							|  |  |  |         conflicts "--formula", "--cask" | 
					
						
							| 
									
										
										
										
											2019-01-30 21:30:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |         named_args [:formula, :cask], max: 1, without_api: true | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2020-02-24 13:25:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |       sig { override.void } | 
					
						
							|  |  |  |       def run | 
					
						
							|  |  |  |         # As this command is simplifying user-run commands then let's just use a | 
					
						
							|  |  |  |         # user path, too. | 
					
						
							|  |  |  |         ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s | 
					
						
							| 
									
										
										
										
											2015-11-23 15:03:12 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |         if args.no_named? | 
					
						
							| 
									
										
										
										
											2024-04-09 10:42:08 +01:00
										 |  |  |           git_log(HOMEBREW_REPOSITORY) | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2024-04-09 10:42:08 +01:00
										 |  |  |           path = T.must(args.named.to_paths.first) | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |           tap = Tap.from_path(path) | 
					
						
							| 
									
										
										
										
											2024-04-09 10:42:08 +01:00
										 |  |  |           git_log path.dirname, path, tap | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2023-03-06 15:00:50 -08:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-03-18 16:57:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |       private | 
					
						
							| 
									
										
										
										
											2020-07-31 17:06:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-09 10:42:08 +01:00
										 |  |  |       sig { params(cd_dir: Pathname, path: T.nilable(Pathname), tap: T.nilable(Tap)).void } | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |       def git_log(cd_dir, path = nil, tap = nil) | 
					
						
							|  |  |  |         cd cd_dir do | 
					
						
							|  |  |  |           repo = Utils.popen_read("git", "rev-parse", "--show-toplevel").chomp | 
					
						
							|  |  |  |           if tap | 
					
						
							|  |  |  |             name = tap.to_s | 
					
						
							|  |  |  |             git_cd = "$(brew --repo #{tap})" | 
					
						
							|  |  |  |           elsif cd_dir == HOMEBREW_REPOSITORY | 
					
						
							|  |  |  |             name = "Homebrew/brew" | 
					
						
							|  |  |  |             git_cd = "$(brew --repo)" | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             name, git_cd = cd_dir | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if File.exist? "#{repo}/.git/shallow" | 
					
						
							|  |  |  |             opoo <<~EOS | 
					
						
							|  |  |  |               #{name} is a shallow clone so only partial output will be shown. | 
					
						
							|  |  |  |               To get a full clone, run: | 
					
						
							|  |  |  |                 git -C "#{git_cd}" fetch --unshallow | 
					
						
							|  |  |  |             EOS | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           git_args = [] | 
					
						
							|  |  |  |           git_args << "--patch" if args.patch? | 
					
						
							|  |  |  |           git_args << "--stat" if args.stat? | 
					
						
							|  |  |  |           git_args << "--oneline" if args.oneline? | 
					
						
							|  |  |  |           git_args << "-1" if args.public_send(:"1?") | 
					
						
							|  |  |  |           git_args << "--max-count" << args.max_count if args.max_count | 
					
						
							| 
									
										
										
										
											2024-04-09 10:42:08 +01:00
										 |  |  |           git_args += ["--follow", "--", path] if path&.file? | 
					
						
							| 
									
										
										
										
											2024-03-31 19:45:55 -07:00
										 |  |  |           system "git", "log", *git_args | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2023-03-06 15:00:50 -08:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2015-11-23 15:03:12 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |