PrePushHook class

The Hook class represents a Git hook configuration that defines a set of tasks to be executed during specific Git hook events. This class allows you to automate checks, validations, or any custom scripts to ensure code quality and consistency across your repository.

Usage

To create a hook, instantiate a concrete hook class such as PreCommitHook, PrePushHook, CommitMsgHook, or AnyHook:

import 'package:hooksman/hooksman.dart';

Hook main() {
  return PreCommitHook(
    tasks: [
      ReRegisterHooks(),
      ShellTask(
        name: 'Lint & Format',
        include: [Glob('**.dart')],
        exclude: [Glob('**.g.dart')],
        commands: (filePaths) => [
          'dart analyze --fatal-infos ${filePaths.join(' ')}',
          'dart format ${filePaths.join(' ')}',
        ],
      ),
      ShellTask(
        name: 'Build Runner',
        include: [Glob('lib/models/**.dart')],
        exclude: [Glob('**.g.dart')],
        commands: (filePaths) => [
          'sip run build_runner build',
        ],
      ),
      ShellTask(
        name: 'Tests',
        include: [Glob('**.dart')],
        exclude: [Glob('hooks/**')],
        commands: (filePaths) => [
          'sip test --concurrent --bail',
        ],
      ),
    ],
  );
}

The tasks parameter is a list of tasks to be executed by the hook. Each task can specify file patterns to include or exclude, and the commands or Dart code to run.

The diffArgs parameter allows you to specify how files are compared with the working directory, index, or commit.

The diffFilters parameter allows you to specify the statuses of files to include or exclude, such as added, modified, or deleted.

The runInParallel parameter allows you to specify whether the top level tasks should be run in parallel. Defaults to true.

The verbose parameter allows you to specify whether the hook should be verbose, which will slow down the execution of the tasks and output detailed information about the tasks being executed. Defaults to false.

Inheritance

Constructors

PrePushHook({required List<HookTask> tasks, String diffFilters = 'ACMR', List<String> diffArgs = const ['@{u}', 'HEAD'], bool runInParallel = true, bool backup = true})
const
PrePushHook.verbose({required List<HookTask> tasks, String diffFilters = 'ACMR', List<String> diffArgs = const ['@{u}', 'HEAD'], bool runInParallel = true, bool backup = true})
const

Properties

backup bool
Whether to snapshot the index and working tree before the tasks run and roll back to it when the hook fails.
finalinherited
diffArgs List<String>
Defaults to '--staged'
finalinherited
diffFilters String
Defaults to 'ACMR'
finalinherited
hashCode int
The hash code for this object.
no setterinherited
props List<Object?>
The list of properties that will be used to determine whether two instances are equal.
no setterinherited
runInParallel bool
Whether to run the top level tasks in parallel
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shouldRunOnEmpty bool
no setterinherited
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
tasks List<HookTask>
finalinherited
verbose bool
finalinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolve(List<String> filePaths) ResolvedHook
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited