From c6b9c40bdf36b71dd9c6a44abd5d598020b2f458 Mon Sep 17 00:00:00 2001 From: amzyang Date: Sat, 26 Oct 2024 21:45:47 +0800 Subject: [PATCH] fix: fatal: cannot lock ref 'HEAD' issue #191 --- cmd/commit.go | 7 +++++++ git/templates/prepare-commit-msg | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/commit.go b/cmd/commit.go index 4f48292..0fc7280 100644 --- a/cmd/commit.go +++ b/cmd/commit.go @@ -41,6 +41,7 @@ var ( defaultTimeout = 30 * time.Second noConfirm = false + noCommit = false ) func init() { @@ -65,6 +66,8 @@ func init() { "show prompt only, don't send request to openai") commitCmd.PersistentFlags().BoolVar(&noConfirm, "no_confirm", false, "skip confirmation prompt") + commitCmd.PersistentFlags().BoolVar(&noCommit, "no_commit", false, + "skip commit") _ = viper.BindPFlag("output.file", commitCmd.PersistentFlags().Lookup("file")) } @@ -321,6 +324,10 @@ var commitCmd = &cobra.Command{ } } + if noCommit { + return nil + } + // git commit automatically color.Cyan("Git record changes to the repository") output, err := g.Commit(commitMessage) diff --git a/git/templates/prepare-commit-msg b/git/templates/prepare-commit-msg index 4da9b71..bb2747d 100755 --- a/git/templates/prepare-commit-msg +++ b/git/templates/prepare-commit-msg @@ -1,5 +1,5 @@ #!/usr/bin/env bash if [[ "$2" != "message" && "$2" != "commit" ]]; then - codegpt commit --file $1 --preview --no_confirm + codegpt commit --file $1 --preview --no_confirm --no_commit fi