From 7bfe85947300347a87496049e338d835cd2b16b7 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 9 Apr 2024 10:42:08 +0100 Subject: [PATCH] cmd/log: various fixes. - Don't pass through `args:` when called with no arguments; these don'T need to be passed and end up breaking things instead. - Make `T.must` as early as possible. - Add a type signature to `git_log` to enable `typed: strict` and catch these sorts of bugs earlier next time. - `--follow` only works with a single file so check if the path is a file before adding it to the arguments. --- Library/Homebrew/cmd/log.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/log.rb b/Library/Homebrew/cmd/log.rb index d783af51b5..d2a4a59474 100644 --- a/Library/Homebrew/cmd/log.rb +++ b/Library/Homebrew/cmd/log.rb @@ -42,16 +42,17 @@ module Homebrew ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s if args.no_named? - git_log(HOMEBREW_REPOSITORY, args:) + git_log(HOMEBREW_REPOSITORY) else - path = args.named.to_paths.first + path = T.must(args.named.to_paths.first) tap = Tap.from_path(path) - git_log T.must(path).dirname, path, tap + git_log path.dirname, path, tap end end private + sig { params(cd_dir: Pathname, path: T.nilable(Pathname), tap: T.nilable(Tap)).void } def git_log(cd_dir, path = nil, tap = nil) cd cd_dir do repo = Utils.popen_read("git", "rev-parse", "--show-toplevel").chomp @@ -79,7 +80,7 @@ module Homebrew 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 - git_args += ["--follow", "--", path] if path.present? + git_args += ["--follow", "--", path] if path&.file? system "git", "log", *git_args end end