From 62753a5ec6b5aa7546b2abb269e6631866ee8573 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 27 Mar 2025 06:09:58 +0300 Subject: [PATCH] create: check that downloaded URL is actually archive My common mistake is to specify release URL, like brew crate https://github.com/hugelgupf/p9/releases/tag/v0.3.0 which gives unpacking errors later. It should be archive instead brew create https://github.com/hugelgupf/p9/archive/refs/tags/v0.3.0.tar.gz Ideally we can try to autodetect the archive from release page, but erroring out if downloaded file is HTML page should be handy for early spotting other URL mistakes too. --- Library/Homebrew/formula_creator.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/formula_creator.rb b/Library/Homebrew/formula_creator.rb index 609d23e8d7..74f1b55176 100644 --- a/Library/Homebrew/formula_creator.rb +++ b/Library/Homebrew/formula_creator.rb @@ -82,7 +82,10 @@ module Homebrew r = Resource.new r.url(@url) r.owner = self - @sha256 = r.fetch.sha256 if r.download_strategy == CurlDownloadStrategy + filepath = r.fetch + raise "Downloaded URL is not archive" if File.read(filepath, 100).strip.start_with?("") + + @sha256 = filepath.sha256 end if @github