appleboy / CodeGPT

A CLI written in Go language that writes git commit messages or do a code review brief for you using ChatGPT AI (gpt-4o, gpt-4-turbo, gpt-3.5-turbo model) and automatically installs a git prepare-commit-msg hook.
MIT License
1.22k stars 109 forks source link

feat: ensure git commit --amend works with prepare-commit-msg hook #179

Closed lee1221ee closed 3 months ago

lee1221ee commented 3 months ago

When the generated message quality is not good, I use codegpt commit --amend to regenerate the message.

But there are still small parts that need to be modified manually.

Using git commit --amend in the current version will cause the following error:

Error: please add your staged changes using git add <files...>

So I modified the git/templates/prepare-commit-msg file, so that codegpt is not executed when git commit --amend is used.

See the Git Hooks documentation

The second is the source of the commit message, and can be: message (if a -m or -F option was given); template (if a -t option was given or the configuration option commit.template is set); merge (if the commit is a merge or a .git/MERGE_MSG file exists); squash (if a .git/SQUASH_MSG file exists); or commit, followed by a commit object name (if a -c, -C or --amend option was given).

appleboy commented 3 months ago

@lee1221ee Thanks.