Repository navigation
feat(hooks): one branch-name rule via vig-utils validate-branch-name - #1806
Merged
Merged
Conversation
Replace the no-commit-to-branch regex with a local validate-branch-name hook in both committed configs and the flake consumer surface, call the same validator from both CI branch-name steps, render the knobs as hook args, and fold every rendered shape of the retired guard on upgrade. Refs: #1760
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
The branch-name rule now has one implementation:
validate-branch-namein vig-utils. Before this, it lived in four hand-kept renderings: theno-commit-to-branchnegative-lookahead regex in both committed hook configs plus the flake surface, and theALLOWEDbash alternations in the scaffold and devkitci.yml. Those renderings disagreed on shape: CI acceptedrelease/X.Y.Zand the local hook did not. Now the local hook, the scaffolded CI step and devkit's own CI step all call the same validator, so the accepted shapes cannot drift.Type of Change
feat-- New featureChanges Made
packages/vig-utils/src/vig_utils/validate_branch_name.py, plus a[project.scripts]entry). It takes only arguments, the same contract asvalidate-commit-range, and never reads.vig-os:--branch: defaults togit symbolic-ref --short HEAD. A detached HEAD, or running outside a repo, passes with a note on stderr. This is whatno-commit-to-branchdid.--typesand--issueless-types: comma-separated and whitespace-tolerant. An empty value falls back to the stock set.--workflow gitflow|trunk: under gitflow,devis also allowed.main,dev(gitflow only),<issueless>/<slug>,<type>/<n>-<slug>,worktree/<n>,renovate/.+andrelease/X.Y.Z. One further tightening: the old regex's bare$let a value with a trailing or embedded newline through (feature/1-foo\n); the validator'sfullmatchrejects it. Unreachable through real git refs, which forbid control characters.(?!dev$), which blockeddev.nix/hooks.nix:branchNamePatternForis replaced byvalidateBranchNameArgs.validate-branch-namehook has two renders, the same wayvalidate-commit-msgdoes. The scaffold YAML usesuv run validate-branch-name. The consumer surface uses the vig-utils store path.always_run,pass_filenames: false,stages: [pre-commit], and nocheckfragment.--flag=valuelines, so each scaffold render owns exactly one line. This keeps them clear ofvalidate-commit-msg's"--types", "…"anchor.no-commit-to-branchentry is gone. It is replaced by arepo: localblock right after the pre-commit-hooks block. The drift gate stays green.branch-typesandissueless-branch-types.nix/hooks.nixdefaultBranchTypes, so the list is not restated.HEAD_REFstill reaches the step only via env.::error::annotation.--workflow, so CI keeps acceptingdevin both models, as it does today.init-workspace.sh:render_branch_types,render_issueless_branch_typesandrender_branch_guard_modelnow rewrite the hook's args throughrender_branch_guard_arg. That sed is scoped to thevalidate-branch-nameentry.render_branch_guard_modelno longer edits comments.Migration of a preserved config: spike result
fold_retired_hook_blockscompares lines verbatim (verbatim_block_range) and keys on one row per historical shape. Verbatim matching alone cannot recognise the rendered variants of the old block, because the pattern line carries the types, the issue-less set and the gitflow/trunk model.retired_block_normalizeruns on the historical needle and on a copy of the consumer file before they are compared. It erases exactly the slots the pre-The branch-name rule exists only inline in ci.yml, so every consumer's local gate must duplicate it (and drifts) #1760 renders wrote:(?!dev$)clause;hooks:list, so the newrepo: localblock cannot be spliced into its place. A new optional 4th row field,template, deletes the retired entry and inserts the replacement at its template position. It reuses the insert path's anchor walk, which I extracted intohook_insert_pointfor both callers. If the file carries no anchor, the fold declines rather than leave the repo with no guard at all.preserved-hook-drift: no-commit-to-branch-pre-1760.hooks.nix.Decisions where the plan was silent
--workflow. This keeps today's CI behaviour of acceptingdevin both models.no-commit-to-branchblocks are not touched, and the new hook is not inserted next to them. The drift warning is the remedy. One consequence: on a gitflow↔trunk switch,render_branch_guard_modelno longer edits such a custom regex.name:is kept asbranch-name (enforce <type>/<issue>-<summary>)for continuity in hook output.assets/workspace/flake.nixkeeps two now-stale comments. It is scaffold-once and preserved, so editing it would put a template diff in front of every consumer on upgrade.Known inherited gap (not fixed here)
The scaffold entry
uv run validate-branch-nameneedsuvon non-Python consumers, exactly asvalidate-commit-msgdoes today. The new entry point reaches consumers the same way that one does:[project.scripts]→nix/vig-utils.nix(whole package) →devtools.nixputs it on PATH in the image and dev-shell, and the flake consumer surface uses the store path.Changelog Entry
Added
validate-branch-name: one branch-name rule for every enforcement point (#1760)Changed
validate-branch-namehook (#1760). This includes the fold and drift reporting for preserved configs.Testing
TDD order:
test(vig-utils)(red) →feat(vig-utils)→test:for the hook, CI and fold (red, 21 failing) →test:for the defaults pin →feat(hooks)→docs.packages/vig-utils/tests/test_validate_branch_name.py: 57 tests covering the rule, the defaults, the CLI,git symbolic-refand detached HEAD.tests/test_scaffold_preserved_hooks.py: the fold is checked for all 3 shapes × 4 renders (stock, trunk, custom types, all knobs + trunk). Further tests cover:tests/test_flake_hooks.py(86 passed): the drift gate, plus consumer-surface args and their semantics, run through the real validator.tests/test_ci_runner.py: both steps call the validator, and the existing behavioural gate tests now execute it.tests/bats/init-workspace.bats(run by file name only): all 312 tests pass.test_imageandtest_integration: 2447 passed.just precommitis green.test_imageandtest_integrationwere left to CI.Refs: #1760