覚えたら書く

IT関係のデベロッパとして日々覚えたことを書き残したいです。twitter: @yyoshikaw

Mac - Homebrewのupdateでエラーになった

結構なこと触ってなかったMacbook で、Homebrew のアップデートをしようとして brew update を実行したら
以下のエラーになりました

yMacBook:~ yki$ brew update
Error:
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
These commands may take a few minutes to run due to the large size of the repositories.
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!


エラー発生時の Homebrew のバージョンは以下の通りでした

yMacBook:~ yki$ brew --version
Homebrew 3.2.17


エラーの意味合い

以下のような感じのようです

Homebrew の更新ファイルを GitHub より取得する際に Git の shallow clone 機能(最新ファイルのみ取得する)を使用して更新データを取得していたが、
この方法は GitHub に負荷がかかるため、GitHubから辞めるようにと要請があった。
そのため、shallow clone を使用しないように設定する必要がある。その設定のためのコマンドを手動で実行してほしい。


エラーの解消方法

エラー発生時に表示されているコマンドを実行して、shallow clone を実行しないように変更します

※このコマンドによって取得するリポジトリのサイズが大きいので、実行に数分かかる場合があります。


コマンドの実行結果の例

yMacBook:~ yki$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
remote: Enumerating objects: 582512, done.
remote: Counting objects: 100% (582503/582503), done.
remote: Compressing objects: 100% (215916/215916), done.
remote: Total 572739 (delta 370710), reused 555791 (delta 353973), pack-reused 0
Receiving objects: 100% (572739/572739), 205.95 MiB | 6.83 MiB/s, done.
Resolving deltas: 100% (370710/370710), completed with 8401 local objects.
From https://github.com/Homebrew/homebrew-core
   85b44dcad6f..e8b65b3b4f1 master     -> origin/master
yMacBook:~ yki$ 
yMacBook:~ yki$ git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
remote: Enumerating objects: 207901, done.
remote: Counting objects: 100% (193205/193205), done.
remote: Compressing objects: 100% (58538/58538), done.
remote: Total 181706 (delta 135876), reused 168717 (delta 123008), pack-reused 0
Receiving objects: 100% (181706/181706), 99.30 MiB | 7.07 MiB/s, done.
Resolving deltas: 100% (135876/135876), completed with 7370 local objects.
From https://github.com/Homebrew/homebrew-cask
   c72519a7d0..a00efcd04d  master     -> origin/master


エラー解消後

エラー解消後は無事に brew update が成功するようになりました。

brew update を実行した後の Homebrew のバージョンは以下の通りでした

yMacBook:~ yki$ brew --version
Homebrew 3.4.0
Homebrew/homebrew-core (git revision 614375043c6; last commit 2022-03-05)
Homebrew/homebrew-cask (git revision a00efcd04d; last commit 2022-03-05)