Skip to content

Commit

Permalink
🧞: Explain and generate git commands using plain English.
Browse files Browse the repository at this point in the history
Install and add pre-commit hook. Show magic with example.
Update commit messages and add main function for pre-commit.
  • Loading branch information
danthelion committed Nov 25, 2023
1 parent 34c079e commit b6d9999
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions git_genie/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import subprocess
import sys

import typer
from langchain.chains import LLMChain
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()

0 comments on commit b6d9999

Please sign in to comment.