File tree Expand file tree Collapse file tree 2 files changed +61
-1
lines changed
Expand file tree Collapse file tree 2 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ var commitCmd = &cobra.Command{
9898 }
9999 message = summarize
100100 } else {
101- message = strings .TrimSpace (summarizeTitle ) + "\n \n " + summarizeDiff
101+ message = strings .TrimSpace (summarizeTitle ) + "\n \n " + strings . TrimSpace ( summarizeDiff )
102102 }
103103
104104 err = os .WriteFile (viper .GetString ("output.file" ), []byte (message ), 0o644 )
Original file line number Diff line number Diff line change 1+ package hook
2+
3+ import (
4+ "embed"
5+ "errors"
6+ "log"
7+ "os"
8+ "path"
9+ "strings"
10+
11+ "github.com/appleboy/CodeGPT/git"
12+ "github.com/appleboy/CodeGPT/util"
13+
14+ "github.com/appleboy/com/file"
15+ )
16+
17+ //go:embed templates/*
18+ var files embed.FS
19+
20+ const (
21+ CommitMessageTemplate = "prepare-commit-msg"
22+ )
23+
24+ func init () {
25+ if err := util .LoadTemplates (files ); err != nil {
26+ log .Fatal (err )
27+ }
28+ }
29+
30+ func Install () error {
31+ hookPath , err := git .Hook ()
32+ if err != nil {
33+ return err
34+ }
35+
36+ target := path .Join (strings .TrimSpace (hookPath ), CommitMessageTemplate )
37+ if file .IsFile (target ) {
38+ return errors .New ("hook file prepare-commit-msg exist." )
39+ }
40+
41+ content , err := util .GetTemplate (CommitMessageTemplate , nil )
42+ if err != nil {
43+ return err
44+ }
45+
46+ return os .WriteFile (target , []byte (content ), 0o755 )
47+ }
48+
49+ func Uninstall () error {
50+ hookPath , err := git .Hook ()
51+ if err != nil {
52+ return err
53+ }
54+
55+ target := path .Join (strings .TrimSpace (hookPath ), CommitMessageTemplate )
56+ if ! file .IsFile (target ) {
57+ return errors .New ("hook file prepare-commit-msg is not exist." )
58+ }
59+ return os .Remove (target )
60+ }
You can’t perform that action at this time.
0 commit comments