branch-name
The built-in Policy branch-name, against commits and pushes to shared branches, lost stashes, merges only people should make: its defaults, its options and a configuration that writes it.
To learn what it guards against and see it at work, read the guide: Git and forge.
Defaults
| Default | Value |
|---|---|
| On by default | no: an entry turns it on |
| Fail mode | closed |
| Timeout | 5000 ms |
| Events | PreToolUse |
| Tools | Bash |
| Agent types | every agent, or as its options set |
Options
| Option | Type | Default | Description |
|---|---|---|---|
allowOnProtectedWhen | ("branch_created_in_same_command" | "merge_in_progress")[] | ["branch_created_in_same_command","merge_in_progress"] | When a commit on a shared branch is allowed: while a merge is in progress (merge_in_progress), or when the same command line opened a new branch first (branch_created_in_same_command). |
baseCandidates | string[] | — | The revisions the branch's own commits are counted from, the first that exists; the default branch on the forge remote, then locally, when absent. |
checkOn | "every_commit" | "first_commit" | "first_commit" | first_commit judges the name only while the branch has no commit of its own; every_commit judges it at each commit. |
copies | object | {"multiTargetSuffix":"-onto-","worktreeSuffix":"-[0-9]+$"} | The suffixes of a branch's copies, which the name is judged without. |
deployBranches | string[] | [] | Globs of deploy branches, which need no such name, beside those of the repository's project. |
exempt | string[] | ["^release-"] | Patterns of branch names that need no <task type>/<slug> name. |
forgeRemote | string | "origin" | The forge's remote; a repository that neither has it configured nor holds refs of it is a scratch repository and is left alone. |
protectedBranches | string[] | — | The shared branches, on which a commit is refused unless allowOnProtectedWhen allows it; the repository's default branch alone when absent. |
slugPattern | string | "^[a-z][a-z0-9]*-[0-9]+(-[a-z0-9]+)*$" | The pattern the slug after the task type must match, opening with a lowercased issue key. |
taskTypes | string[] | ["chore","epic","feature","fix","refactor"] | The task types a branch name may start with, <task type>/<slug>. |
Example
A configuration that writes every option, a comment above each:
import { defineConfig } from '@microeinhundert/harness-kit';
export default defineConfig({
// The Policy entries, in the order their Decisions merge in.
policies: [
{
// The Policy's name, unique in the configuration; messages and logs name the Policy by it.
id: 'branch-name',
// The constructor's options, which it decodes.
options: {
// When a commit on a shared branch is allowed: while a merge is in progress
// (`merge_in_progress`), or when the same command line opened a new branch first
// (`branch_created_in_same_command`).
allowOnProtectedWhen: ['branch_created_in_same_command', 'merge_in_progress'],
// The revisions the branch's own commits are counted from, the first that exists; the
// default branch on the forge remote, then locally, when absent.
baseCandidates: ['origin/main'],
// `first_commit` judges the name only while the branch has no commit of its own;
// `every_commit` judges it at each commit.
checkOn: 'first_commit',
// The suffixes of a branch's copies, which the name is judged without.
copies: {
// The text that opens the suffix of a branch's copy made for one target, such as `-onto-`
// in `feat-x-onto-release-3`.
multiTargetSuffix: '-onto-',
// The pattern of the suffix a worktree's copy of a branch adds, such as `-[0-9]+$` for
// `feat-x-2`, a copy of `feat-x`.
worktreeSuffix: '-[0-9]+$',
},
// Globs of deploy branches, which need no such name, beside those of the repository's
// project.
deployBranches: ['release/*'],
// Patterns of branch names that need no `<task type>/<slug>` name.
exempt: ['^release-'],
// The forge's remote; a repository that neither has it configured nor holds refs of it is a
// scratch repository and is left alone.
forgeRemote: 'origin',
// The shared branches, on which a commit is refused unless `allowOnProtectedWhen` allows
// it; the repository's default branch alone when absent.
protectedBranches: ['release/*'],
// The pattern the slug after the task type must match, opening with a lowercased issue key.
slugPattern: '^[a-z][a-z0-9]*-[0-9]+(-[a-z0-9]+)*$',
// The task types a branch name may start with, `<task type>/<slug>`.
taskTypes: ['chore', 'epic', 'feature', 'fix', 'refactor'],
},
// The name of the kit's Policy constructor that builds the Policy.
use: 'branch-name',
},
],
});command-policy
The built-in Policy command-policy, against dangerous command lines: production kubectl, the wrong package manager, a subagent that should only read: its defaults, its options and a configuration that writes it.
push-target
The built-in Policy push-target, against commits and pushes to shared branches, lost stashes, merges only people should make: its defaults, its options and a configuration that writes it.