Skip to content

Commit a37cd88

Browse files
authored
feat: ensure git commit --amend works with prepare-commit-msg hook (#179)
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](https://git-scm.com/docs/githooks#_prepare_commit_msg) > 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).
1 parent 728590b commit a37cd88

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

git/templates/prepare-commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/sh
22

3-
if [[ "$2" != "message" ]]; then
3+
if [[ "$2" != "message" && "$2" != "commit" ]]; then
44
codegpt commit --file $1 --preview
55
fi

0 commit comments

Comments
 (0)