git_hooks 0.0.3 copy "git_hooks: ^0.0.3" to clipboard
git_hooks: ^0.0.3 copied to clipboard

outdated

Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...).

git_hooks #

https://img.shields.io/github/license/xuzhongpeng/git_hooks Pub

git_hooks can prevent bad git commit,git push and more easy in dart and flutter!

Install #

dev_dependencies:
  git_hooks: ^0.0.1

then

pub get

or

flutter pub get

and then activate it in shell

pub global activate git_hooks

Uninstall #

dev_dependencies:
  - git_hooks: ^0.0.1
pub get

or

flutter pub get

and

pub global deactivate git_hooks

create files in .git/hooks #

We can create git hooks with

git_hooks create

It will create some hooks files in .git/hooks. You can check whether the installation is correct by judging whether the file(".git/hooks/commit-msg" and other fils) exists.

It will create a file git_hooks.dart in your project root directory.

Using #

You can change git_hooks.dart

void main(List arguments) {
  Map<Git, UserBackFun> params = {
    Git.commitMsg: commitMsg,
    Git.preCommit: preCommit
  };
  change(arguments, params);
}

Future<bool> commitMsg() async {
  Directory rootDir = Directory.current;
  File myFile = new File(rootDir.path + "/.git/COMMIT_EDITMSG");
  print("commit message is '${myFile.readAsStringSync()}'");
  print('this is commitMsg');
  return false;
}
Future<bool> preCommit() async {
  print('this is pre-commit');
  return true;
}

If you want interrupt your commit or push,you can return false.Then you can return true if only nothing to do.

add file to git

git add .
git commit -m 'some messages'

If it output following.Congratulations on your successful use of it.

start pre-commit hook...               /
-this is pre-commit

1.1s
start prepare-commit-msg hook...       /
1.1s
start commit-msg hook...               /
\commit message is 'some messages'
this is commitMsg

1.2s

Define our own hook functions #

You can use enum Git to Define more hooks functions.

There is all hooks provide

enum Git {
  applypatchMsg,
  preApplypatch,
  postApplypatch,
  preCommit,
  prepareCommitMsg,
  commitMsg,
  postCommit,
  preRebase,
  postCheckout,
  postMerge,
  prePush,
  preReceive,
  update,
  postReceive,
  postUpdate,
  pushToCheckout,
  preAutoGc,
  postRewrite,
  sendemailValidate
}

You can click here to learn more about git hooks.

You can define own function.For example,I want define a hook what can verify commit message starts with 'fix:'.

git_hooks.dart

import "package:git_hooks/git_hooks.dart";
import "dart:io";
import "dart:path/path.dart" as path;

void main(List arguments) {
  Map<Git, UserBackFun> params = {Git.commitMsg: commitMsg};
  change(arguments, params);
}

Future<bool> commitMsg() async {
  Directory rootDir = Directory.current;
  File myFile =
      new File(path.fromUri(path.toUri("${rootDir.path}/.git/COMMIT_EDITMSG")));//We use 'path' for windows and MAC compatibility
  String commitMsg = myFile.readAsStringSync();
  if (commitMsg.startsWith('fix:')) {
    return true;
  } else
    return false;
}
29
likes
0
pub points
80%
popularity

Publisher

unverified uploader

Prevents bad commit or push (git hooks, pre-commit/precommit, pre-push/prepush, post-merge/postmerge and all that stuff...).

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

path, yaml

More

Packages that depend on git_hooks