diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-17 11:03:53 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-17 11:03:53 +0800 |
commit | 894cf6f88a640c2bc796caa3c61e5b7ed787683b (patch) | |
tree | 3381b3e2aeb9d740c191edfdf670dd32ad7939c5 /git_init.go | |
parent | README.md: s/PGP/SSH/ for commit signature verification (diff) | |
download | forge-894cf6f88a640c2bc796caa3c61e5b7ed787683b.tar.gz forge-894cf6f88a640c2bc796caa3c61e5b7ed787683b.tar.zst forge-894cf6f88a640c2bc796caa3c61e5b7ed787683b.zip |
git_init.go: git_bare_init_with_default_hooks
Diffstat (limited to '')
-rw-r--r-- | git_init.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/git_init.go b/git_init.go new file mode 100644 index 0000000..466628f --- /dev/null +++ b/git_init.go @@ -0,0 +1,28 @@ +package main + + +import ( + "github.com/go-git/go-git/v5" + git_format_config "github.com/go-git/go-git/v5/plumbing/format/config" +) + +func git_bare_init_with_default_hooks(repo_path string) (err error) { + repo, err := git.PlainInit(repo_path, true) + if err != nil { + return err + } + + git_config, err := repo.Config() + if err != nil { + return err + } + + git_config.Raw.SetOption("core", git_format_config.NoSubsection, "hooksPath", config.Hooks.Execs) + + err = repo.SetConfig(git_config) + if err != nil { + return err + } + + return nil +} |