CommitMsgHook class
A hook that runs for Git's commit-msg event.
Git passes the path to the commit message file as $1. After
executeHook binds args, messageFile holds that path. Full args and
stdin are also available via hookContext from
package:hooksman/hooksman.dart.
// hooks/commit_msg.dart
import 'package:hooksman/hooksman.dart';
Hook main() {
return CommitMsgHook(
tasks: [
ShellTask.always(
name: 'Ensure message file exists',
commands: (_) {
final file = hookContext.messageFile ?? '';
return ['test -f "$file"'];
},
),
],
);
}
Prefer reading messageFile (or hookContext.messageFile) from a
Dart task when you need the message contents in Dart. This hook always
runs even when the working-tree diff is empty.
Constructors
-
CommitMsgHook({required List<
HookTask> tasks, String? messageFile, List<String> diffArgs = const [], String diffFilters = '', bool runInParallel = true, bool backup = true}) -
const
-
CommitMsgHook.verbose({required List<
HookTask> tasks, String? messageFile, List<String> diffArgs = const [], String diffFilters = '', 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
- messageFile → String?
-
Path to the commit message file (
$1from Git). Bound at runtime.final -
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 setteroverride
- stringify → bool?
-
If set to
true, thetoStringmethod will be overridden to output this instance'sprops.no setterinherited -
tasks
→ List<
HookTask> -
finalinherited
- verbose → bool
-
finalinherited
Methods
-
bindMessageFile(
String? path) → CommitMsgHook - Returns a copy with messageFile set from hook args.
-
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