Skip to Content
harness-kit

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

DefaultValue
On by defaultno: an entry turns it on
Fail modeclosed
Timeout5000 ms
EventsPreToolUse
ToolsBash
Agent typesevery agent, or as its options set

Options

OptionTypeDefaultDescription
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).
baseCandidatesstring[]—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.
copiesobject{"multiTargetSuffix":"-onto-","worktreeSuffix":"-[0-9]+$"}The suffixes of a branch's copies, which the name is judged without.
deployBranchesstring[][]Globs of deploy branches, which need no such name, beside those of the repository's project.
exemptstring[]["^release-"]Patterns of branch names that need no <task type>/<slug> name.
forgeRemotestring"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.
protectedBranchesstring[]—The shared branches, on which a commit is refused unless allowOnProtectedWhen allows it; the repository's default branch alone when absent.
slugPatternstring"^[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.
taskTypesstring[]["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',
    },
  ],
});

On this page