diff --git a/README.md b/README.md index ea0a730..acb4efb 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,37 @@ Generate & explain git commands using plain english. Generated command: git commit -m 'Update README with commit message example and instructions' ``` +### Generate commit messages as a pre-commit hook + +#### Install pre-commit + +```shell +pip install pre-commit +``` + +#### Add pre-commit hook + +```yaml +repos: + - repo: https://github.com/danthelion/git-genie + rev: "v0.3.0" + hooks: + - id: git-genie + args: [ '--mode=append' ] # or --mode=replace +``` + +#### Watch the magic happen + +```shell +~/Personal/git-genie-pre-commit main* ❯ git add . && git commit -m "test" + +git-genie................................................................Passed + +[main 0dc8c69] test 🧞: Specify specific revision and add '--mode=replace' argument to git-genie hook. + + 1 file changed, 2 insertions(+), 1 deletion(-) +``` + ### Generate & Explain complex git commands using plain english ![example](example.png) diff --git a/git_genie/main.py b/git_genie/main.py index 90003e2..bd458a4 100644 --- a/git_genie/main.py +++ b/git_genie/main.py @@ -1,6 +1,5 @@ import argparse import subprocess -import sys import typer from langchain.chains import LLMChain @@ -274,7 +273,7 @@ def main( ) -def update_commit_message(filename, mode): +def update_commit_message(filename: str, mode: str = "append"): with open(filename, "r+") as fd: contents = fd.readlines() commit_msg = contents[0].rstrip("\r\n") @@ -304,8 +303,8 @@ def pre_commit(argv=None): parser.add_argument("filenames", nargs="+") parser.add_argument("--mode", nargs="?", const=append, default=append, choices=[append, replace]) args = parser.parse_args(argv) - update_commit_message(args.filenames[0], mode="append") + update_commit_message(args.filenames[0], mode=args.mode) if __name__ == "__main__": - sys.exit(pre_commit()) + app()