Skip to content

Ignore user-configured Git hooks for tap operations - #23352

Merged
MikeMcQuaid merged 3 commits into
Homebrew:mainfrom
boblail:lail/tap-ignore-core-hookspath
Jul 29, 2026
Merged

Ignore user-configured Git hooks for tap operations#23352
MikeMcQuaid merged 3 commits into
Homebrew:mainfrom
boblail:lail/tap-ignore-core-hookspath

Conversation

@boblail

@boblail boblail commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

A global core.hooksPath (e.g. set by git lfs install) breaks brew tap and brew update: Git hooks run with Homebrew's filtered PATH, which lacks git-lfs, so every tap clone and tap update fails. Pass -c core.hooksPath=/dev/null to tap and update Git operations, as package/scripts/postinstall already does for the installer. Requested in #21621; same failure mode as #4988, #7014 and https://github.com/orgs/Homebrew/discussions/5047. No other user Git configuration is bypassed, so credential helpers for private taps keep working (cf. #22774).

To reproduce:

$ git config --global core.hooksPath ~/.githooks
$ git lfs update  # installs the stock LFS hooks into ~/.githooks
$ brew tap homebrew/command-not-found
==> Tapping homebrew/command-not-found
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-command-not-found'...
This repository is configured for Git LFS but 'git-lfs' was not found on your path.
Error: Failure while executing; `git clone ...` exited with 2.

  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • AI was used to generate or assist with generating this PR.

Written with Claude Code, reviewed and directed by me. Verified with a red/green RSpec cycle (the new spec reproduces the hook failure before the fix) and a manual end-to-end reproduction: brew tap of a local repository with a hostile global core.hooksPath fails on main and succeeds with this change, with the hook confirmed not to run. brew lgtm passes locally.


🤖 Generated with Claude Code

Comment thread Library/Homebrew/tap.rb Outdated

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good when 🟢

@boblail
boblail force-pushed the lail/tap-ignore-core-hookspath branch from 1918e98 to d1246ef Compare July 29, 2026 16:21
@boblail
boblail marked this pull request as ready for review July 29, 2026 16:31
Copilot AI review requested due to automatic review settings July 29, 2026 16:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents user-defined Git hooks (via core.hooksPath, commonly set by git lfs install) from running during Homebrew tap and update Git operations, avoiding failures caused by Homebrew’s sanitized PATH (e.g., missing git-lfs).

Changes:

  • Prepends git -c core.hooksPath=/dev/null to Tap#git_command! and related worktree operations.
  • Wraps git invocations in cmd/update.sh and cmd/update-reset.sh with the same -c core.hooksPath=/dev/null behavior.
  • Updates/adds RSpec coverage to exercise the new hook-bypass behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
Library/Homebrew/tap.rb Forces core.hooksPath to null for tap clone/fetch and worktree add operations.
Library/Homebrew/cmd/update.sh Ensures brew update Git calls ignore core.hooksPath hooks.
Library/Homebrew/cmd/update-reset.sh Ensures brew update-reset Git calls ignore core.hooksPath hooks.
Library/Homebrew/test/tap_spec.rb Updates expectations for new Git args and adds a spec intended to cover hook bypassing.
Comments suppressed due to low confidence (1)

Library/Homebrew/tap.rb:726

  • Same as above: this comment refers to "user-configured hooks", but the implementation forces core.hooksPath for the invocation regardless of config scope. Rewording helps avoid implying only global config is affected.
        # Ignore user-configured hooks as in `git_command!`.
        worktree_args = ["-c", "core.hooksPath=#{File::NULL}", "-C", worktree_source_tap_path, "worktree", "add"]
        worktree_args << "--quiet" if quiet

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/test/tap_spec.rb
Comment thread Library/Homebrew/tap.rb Outdated
Comment thread Library/Homebrew/cmd/update.sh Outdated
Comment thread Library/Homebrew/cmd/update-reset.sh Outdated
@boblail

boblail commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Applying Copilot's suggestions...

boblail and others added 3 commits July 29, 2026 09:54
A global `core.hooksPath` (e.g. set by `git lfs install`) breaks
`brew tap` and `brew update`: hooks run with Homebrew's filtered
`PATH`, which lacks `git-lfs`, so every tap clone or update fails.

Pass `-c core.hooksPath=/dev/null` to tap and update Git operations,
as `package/scripts/postinstall` already does for the installer.

Requested in Homebrew#21621.
The hook spec now verifies via a side effect that the hook never
executes, rather than only that `git clone` succeeds. Comments no
longer say "user-configured" since `-c core.hooksPath` overrides
every configuration scope.
@boblail
boblail force-pushed the lail/tap-ignore-core-hookspath branch from d1246ef to cbd163b Compare July 29, 2026 16:57

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Jul 29, 2026
Merged via the queue into Homebrew:main with commit 64a9bfc Jul 29, 2026
41 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants