add function
Adds a git hook by copying from the sample file. If the hook already exists, it skips the addition.
Implementation
Future<void> add(String hookName, bool verbose) async {
final hookFile = File('${Consts.herdsmanDirPath}/$hookName.sample');
if (hookFile.existsSync()) {
final newFile = File('${Consts.herdsmanDirPath}/$hookName');
if (newFile.existsSync()) {
print('⚠️ Git hook $hookName already exists. Skipping...');
return;
}
final file = hookFile.copySync('${Consts.herdsmanDirPath}/$hookName');
if (verbose) print('🔨 Creating git hook: $hookName');
file.createSync();
if (verbose) print('📄 Created git hook file: $hookName');
hookFile.deleteSync();
if (verbose) print('🗑️ Deleting sample git hook: $hookName.sample');
print('✅ Add git hook: $hookName');
} else {
print('⚠️ Git hook $hookName already exists. Skipping...');
}
}