active function

void active(
  1. bool verbose
)

Activates all git hooks by setting the core.hooksPath and making hook files executable. If any error occurs during the process, it writes the error to stderr and exits with code 1.

Implementation

void active(bool verbose) {
  final result = Process.runSync('git', [
    'config',
    'core.hooksPath',
    Consts.herdsmanDirPath,
  ]);

  if (result.exitCode != 0) {
    stderr.write(result.stderr);
    exit(1);
  }

  for (final hook in [...getHooks(), ...deactiveHooks()]) {
    final file = File(hook);
    if (file.existsSync()) {
      final result = Process.runSync('chmod', ['+x', hook], runInShell: true);

      if (result.exitCode != 0) {
        stderr.write(result.stderr);
        exit(1);
      } else {
        print('✅ Activated git hook: $hook');
      }
    }
  }
  print('🎉 All git hooks are activated.');
}