From bd1774d37e1bfdb72e8f772883715e3163b08672 Mon Sep 17 00:00:00 2001 From: Ilya Kulakov Date: Fri, 28 Jun 2024 15:46:00 -0700 Subject: [PATCH] extract: Add the --revision argument When pinning formula alongside its dependencies it's important to limit the search scope. --- Library/Homebrew/dev-cmd/extract.rb | 7 +++++-- .../sorbet/rbi/dsl/homebrew/dev_cmd/extract.rbi | 3 +++ Library/Homebrew/test/dev-cmd/extract_spec.rb | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/extract.rb b/Library/Homebrew/dev-cmd/extract.rb index af8e3b6375d8a7..a7455e52042bdb 100644 --- a/Library/Homebrew/dev-cmd/extract.rb +++ b/Library/Homebrew/dev-cmd/extract.rb @@ -22,6 +22,8 @@ class Extract < AbstractCommand a formula from a tap that is not `homebrew/core` use its fully-qualified form of `/``/`. EOS + flag "--revision=", + description: "Search for the specified of starting at instead of HEAD." flag "--version=", description: "Extract the specified of instead of the most recent." switch "-f", "--force", @@ -49,6 +51,7 @@ def run destination_tap.install unless destination_tap.installed? repo = source_tap.path + default_revision = args.revision || "HEAD" pattern = if source_tap.core_tap? [source_tap.new_formula_path(name), repo/"Formula/#{name}.rb"].uniq else @@ -64,7 +67,7 @@ def run test_formula = T.let(nil, T.nilable(Formula)) result = "" loop do - rev = rev.nil? ? "HEAD" : "#{rev}~1" + rev = rev.nil? ? default_revision : "#{rev}~1" rev, (path,) = Utils::Git.last_revision_commit_of_files(repo, pattern, before_commit: rev) if rev.nil? && source_tap.shallow? odie <<~EOS @@ -112,7 +115,7 @@ def run result = Utils::Git.last_revision_of_file(repo, file) else file = files.fetch(0).realpath - rev = T.let("HEAD", T.nilable(String)) + rev = T.let(default_revision, T.nilable(String)) version = Formulary.factory(file).version result = File.read(file) end diff --git a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/extract.rbi b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/extract.rbi index 79e9595f95f7af..ef09fabb8f96fc 100644 --- a/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/extract.rbi +++ b/Library/Homebrew/sorbet/rbi/dsl/homebrew/dev_cmd/extract.rbi @@ -17,6 +17,9 @@ class Homebrew::DevCmd::Extract::Args < Homebrew::CLI::Args sig { returns(T::Boolean) } def force?; end + sig { returns(T.nilable(String)) } + def revision; end + sig { returns(T.nilable(String)) } def version; end end diff --git a/Library/Homebrew/test/dev-cmd/extract_spec.rb b/Library/Homebrew/test/dev-cmd/extract_spec.rb index f6e6104255a0b2..da4486fd345d32 100644 --- a/Library/Homebrew/test/dev-cmd/extract_spec.rb +++ b/Library/Homebrew/test/dev-cmd/extract_spec.rb @@ -44,6 +44,16 @@ expect(Formulary.factory(path).version).to eq "0.2" end + it "retrieves the most recent version of formula starting at the specified revision", :integration_test do + path = target[:path]/"Formula/testball@0.1.rb" + expect { brew "extract", "testball", target[:name], "--revision=HEAD~1" } + .to output(/^#{path}$/).to_stdout + .and not_to_output.to_stderr + .and be_a_success + expect(path).to exist + expect(Formulary.factory(path).version).to eq "0.1" + end + it "retrieves the specified version of formula", :integration_test do path = target[:path]/"Formula/testball@0.1.rb" expect { brew "extract", "testball", target[:name], "--version=0.1" }