MacOS – How to find source formula of brew package (github repo)

githomebrewmacos

How can I find the sources and changes for a given brew package?

I'm having an issue with a package that's installed via brew on a cloud instance whose image I don't control. I'm trying to figure out if the issue is a result of the package installed from brew or not.

I want to find the source for that package in the brew system (that is, the git or other VCS where the formula/cask are maintained) and see what changes were made to the package in the past few days/weeks, look through the commits, and read their CHANGELOG.

How can I determine the repository for a given package on brew and look through its commits over time?

Best Answer

If your package is in homebrew-core, then you can view the recipe's ruby source and its changes from the homebrew-core repo in the Formula directory

Unfortunately, finding the recipe for a given brew package on github.com may be tricky, since there's too many dirs and GitHub may truncate or refuse the output.

Instead, you can get and list all the homebrew forumulas with the following commands in zsh:

git clone https://github.com/Homebrew/homebrew-core.git
cd homebrew-core/Formula
find . | grep -i <package>

Then you can show the history of a given formula with git log

For example, I was able to discover that the python@3.7 package in brew changed yesterday:

user@host ~ % git clone https://github.com/Homebrew/homebrew-core.git
Cloning into 'homebrew-core'...
remote: Enumerating objects: 77, done.
remote: Counting objects: 100% (77/77), done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 791472 (delta 51), reused 59 (delta 43), pack-reused 791395
Receiving objects: 100% (791472/791472), 316.25 MiB | 9.55 MiB/s, done.
Resolving deltas: 100% (529456/529456), done.
Updating files: 100% (5476/5476), done.
user@host ~ % cd homebrew-core/Formula
user@host Formula %

user@host Formula % find . | grep -i python
./python-yq.rb
./boost-python.rb
./python-markdown.rb
./app-engine-python.rb   
./ipython.rb
./python@3.7.rb
./gst-python.rb
./micropython.rb
./wxpython.rb
./reorder-python-imports.rb
./python@3.8.rb
./boost-python3.rb
user@host ~ %

user@host Formula % git log master -n1 python@3.7.rb
commit 10d3df6c9a263c4e7dea4752a00a1b98ddc9c05a
Author: BrewTestBot <1589480+BrewTestBot@users.noreply.github.com>
Date:   Wed Sep 9 00:40:17 2020 +0000

    python@3.7: update 3.7.9 bottle.
user@host Formula %