Hook class sealed

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 the Hook class with the desired tasks and optional parameters:

import 'package:hooksman/hooksman.dart';

Hook main() {
  return Hook(
    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 backupFiles parameter specifies whether the original files should be backed up before running the hook.

Implementers

Properties

diffArgs List<String>
Defaults to '--staged'
final
diffFilters String
Defaults to 'ACMR'
final
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 setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
shouldRunOnEmpty bool
no setter
stringify bool?
If set to true, the toString method will be overridden to output this instance's props.
no setterinherited
tasks List<HookTask>
final
verbose bool
final

Methods

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

Operators

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