feat(git): add a hook that can enforce powerful commit selection policies - #2165
Open
FlippingBinary wants to merge 3 commits into
Open
FlippingBinary wants to merge 3 commits into
FlippingBinary wants to merge 3 commits into
Conversation
1 task
This branch has not been deployed
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.
Description
Resolves #2141 by introducing a
CommitHook— a flexible extension point that lets users implement their own commit-selection logic (such as a minimum age requirement) without forcing a built-in policy on everyone.The original issue asked for a built-in minimum commit age feature to reduce churn from broken commits. There was resistance to shipping such a feature directly: aging is one of many possible rules users might want (such as skipping CI bot commits, commits with a rapid followup, fresh commits, etc.), and baking a specific policy into core would either impose one user's preferences on everyone or require a pile of configuration that overlaps with this generic mechanism.
This change provides the generic mechanism instead and lets users decide what to enforce.
What it does:
commitfield todefaultsand allows it or the per-speccommitto contain aCommitHookfunction.GitTargetdescribing the commit that would otherwise be selected (resolved tag, version, or latest on the branch) and returns either:GitTarget(e.g. the target itself, or one of its parents viatarget:parent()).GitTargetexposes methods useful for writing rules::date(),:age(),:short(),:message(),:author(),:parent().Examples:
Skip commits newer than 7 days (the original use case from the issue):
Skip commits followed up within 3 days:
Skip commits authored by Github Copilot:
Notes:
As an aside, this pull request includes a commit that modifies the test framework. Under
nvim -l, mini.test's scheduler-based queue was being torn down by Neovim's exit sequence before tests drained, which setvim.v.exitingmid-flight and caused lazy's async executor to hang. The test entrypoint now blocks onMiniTest.is_executing()so mini.test's ownquit_on_finishruns cleanly. If desired, that commit can be spun off or removed entirely. I just needed it for the tests to work, but there probably is a better way to solve that particular problem.Related Issue(s)
Fixes #2141
Screenshots
N/A