git_hooks 0.1.1 git_hooks: ^0.1.1 copied to clipboard
Using dart to prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...).
import "package:git_hooks/git_hooks.dart";
import "dart:io";
void main(List arguments) {
Map<Git, UserBackFun> params = {
Git.commitMsg: commitMsg,
Git.preCommit: preCommit
};
GitHooks.call(arguments, params);
}
Future<bool> commitMsg() async {
String commitMsg = Utils.getCommitEditMsg();
if (commitMsg.startsWith('fix:')) {
return true; // you can return true let commit go
} else
return false;
}
Future<bool> preCommit() async {
try {
ProcessResult result = await Process.run('dartanalyzer', ['bin']);
print(result.stdout);
if (result.exitCode != 0) return false;
} catch (e) {
return false;
}
return true;
}