feat: Add trusted remotes to trust repositories by url - #203
Open
ds-stefanro wants to merge 1 commit into
Open
Conversation
Add the `githooks.trustedRemotes` configuration holding glob patterns which are matched against the url of the remote `origin` of a repository. Every repository whose remote url matches any pattern is a trusted repository, meaning all its current and future hooks run without showing the trust prompt and without needing the `.githooks/trust-all` marker. This allows to trust all repositories of an organization one trusts anyway, e.g. `--add 'https://github.com/my-org/**'`, instead of accepting the trust prompt once per clone. Details: - The url is matched as configured in `remote.origin.url`, no normalization is done, meaning `https://` and scp syntax urls need separate patterns. Not matching a pattern only means more prompts, therefore this fails safe. - Matching uses `/` as separator on all platforms (`GlobMatchSlashes`), therefore `*` does not match over `/` but `**` does. - A repository without a remote `origin` is never trusted, also not by a pattern like `*`. - An explicit `githooks.trustAll` setting in a repository takes precedence, meaning a repository whose trust the user denied stays untrusted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In an organization setting, developers clone many repositories from the same trusted source (e.g. their company's GitHub organization). Currently each fresh clone requires answering the trust prompt (per hook, or once per clone with the
trust-allmarker), which adds friction without a real security decision — the organization's repositories are review-gated and trusted anyway.What this adds
A new global/local Git configuration
githooks.trustedRemotesholding glob patterns which are matched against the url of the remoteoriginof a repository. Every repository whose remote url matches any pattern is a trusted repository: all its current and future hooks run without showing the trust prompt and without needing the.githooks/trust-allmarker.git hooks config trusted-remotes --add 'https://github.com/my-org/**'Design details
remote.origin.url, no normalization is done, meaninghttps://and scp syntax urls need separate patterns. Not matching a pattern only means more prompts, therefore this fails safe./as separator on all platforms (GlobMatchSlashes), therefore*does not match over/but**does.originis never trusted, also not by a pattern like*.githooks.trustAllsetting in a repository takes precedence, meaning a repository whose trust the user denied stays untrusted.Includes a
git hooks config trusted-remotesCLI command (--add,--remove,--print), documentation (README section and CLI docs), and unit tests for the matching and precedence logic.🤖 Generated with Claude Code