Skip to Content
harness-kit

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.

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
Timeout10000 ms
EventsPreToolUse
ToolsBash
Agent typesevery agent, or as its options set

Options

OptionTypeDefaultDescription
allowDryRunbooleantrueWhether a --dry-run push passes.
copiesobject{"multiTargetSuffix":"-onto-","worktreeSuffix":"-[0-9]+$"}The suffixes of a branch's copies.
deployBranchesstring[][]Globs of deploy branches, which the pull request head check leaves alone, beside the project's.
forgeRemotestring"origin"The remote the forge's pull requests live on.
protectedBranchesstring[]—The shared branches no push may write to, directly, through the branch's upstream or through push.default=upstream; the default branch of the remote the push names when absent.
pullRequestHeadobject{"enabled":true,"exempt":["assets/"],"keyPattern":"^([A-Za-z][A-Za-z0-9]*-[0-9]+)","limit":500,"timeoutMillis":5000}The check that refuses a push to a copy of a branch that already has an open pull request.
unknownLocation"allow" | "refuse""refuse"refuse refuses a push that writes the current branch from a folder the guard cannot follow; allow lets it run.

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: 'push-target',
      // The constructor's options, which it decodes.
      options: {
        // Whether a `--dry-run` push passes.
        allowDryRun: true,
        // The suffixes of a branch's copies.
        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 the pull request head check leaves alone, beside the
        // project's.
        deployBranches: ['release/*'],
        // The remote the forge's pull requests live on.
        forgeRemote: 'origin',
        // The shared branches no push may write to, directly, through the branch's upstream or
        // through `push.default=upstream`; the default branch of the remote the push names when
        // absent.
        protectedBranches: ['release/*'],
        // The check that refuses a push to a copy of a branch that already has an open pull
        // request.
        pullRequestHead: {
          // Whether the gate runs; it is on unless `false`.
          enabled: true,
          // Branch prefixes the gate leaves alone, such as `assets/`.
          exempt: ['assets/'],
          // The pattern of the issue key, read from a branch's last path segment (its first group,
          // or the whole match).
          keyPattern: '^([A-Za-z][A-Za-z0-9]*-[0-9]+)',
          // How many open pull requests the forge's `pr_list` is asked for; an answer that fills
          // the limit counts as unknown and passes.
          limit: 500,
          // How many milliseconds the forge's `pr_list` may take; no answer in time counts as
          // unknown and passes.
          timeoutMillis: 5000,
        },
        // `refuse` refuses a push that writes the current branch from a folder the guard cannot
        // follow; `allow` lets it run.
        unknownLocation: 'refuse',
      },
      // The name of the kit's Policy constructor that builds the Policy.
      use: 'push-target',
    },
  ],
});

On this page