Homebrew で Error: homebrew-core is a shallow clone が出て brew update が実行できない問題

HomebrewmacOS

2020 年 12 月以降に Homebrew で brew update をしようとすると次のようなエラーが出て処理が実行できないことがあります。

Error: homebrew-core is a shallow clone. To `brew update` first run:
  git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
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. 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-cask を利用している場合はそちらでも起こります。

Error: homebrew-cask is a shallow clone. To `brew update` first run:
  git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow
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-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 はこれまで Git リポジトリの shallow clone を利用してきましたが、 shallow clone の更新はどうしても重たい処理になってしまうとのことで、 GitHub からの要請を受けて shallow ではない完全な clone を使う形に変更になったようです。

解決策は単純で、エラー文で示されたコマンドを実行するだけで OK です(リポジトリのパスは環境によって異なるので、以下のコマンドをコピペするのではなく、各環境のエラー文に示されているものを使ってください)。

git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow

homebrew-cask も利用している場合はそちらの分も実行します。

git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow

git -C XXX fetch --unshallow というのは、指定されたパスにあるリポジトリクローンを shallow なものから完全なものに変更するためのコマンドです。

ということで、厳密に言うとこれはエラーというよりも「変更が加わったために手作業での対応してね」というメッセージでした。

該当する pull request はこちらです:

参考:


アバター
後藤隼人 ( ごとうはやと )

ソフトウェア開発やマーケティング支援などをしています。詳しくはこちら