aboutsummaryrefslogtreecommitdiff
path: root/forged/internal/unsorted/git_init.go
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-04-06 09:26:46 +0800
committerRunxi Yu <me@runxiyu.org>2025-04-06 09:27:53 +0800
commitda1d8f4e7c332c7109427915e6459b10209cedce (patch)
tree280b921be3b51f93d82d916b4eaa89387b7102cc /forged/internal/unsorted/git_init.go
parentgit2c, git2d: Rename cmd1 and cmd2 descriptively (diff)
downloadforge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.gz
forge-da1d8f4e7c332c7109427915e6459b10209cedce.tar.zst
forge-da1d8f4e7c332c7109427915e6459b10209cedce.zip
Move the Go stuff to ./forged/v0.1.32
Diffstat (limited to 'forged/internal/unsorted/git_init.go')
-rw-r--r--forged/internal/unsorted/git_init.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/forged/internal/unsorted/git_init.go b/forged/internal/unsorted/git_init.go
new file mode 100644
index 0000000..a9bba78
--- /dev/null
+++ b/forged/internal/unsorted/git_init.go
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>
+
+package unsorted
+
+import (
+ "github.com/go-git/go-git/v5"
+ gitConfig "github.com/go-git/go-git/v5/config"
+ gitFmtConfig "github.com/go-git/go-git/v5/plumbing/format/config"
+)
+
+// gitInit initializes a bare git repository with the forge-deployed hooks
+// directory as the hooksPath.
+func (s *Server) gitInit(repoPath string) (err error) {
+ var repo *git.Repository
+ var gitConf *gitConfig.Config
+
+ if repo, err = git.PlainInit(repoPath, true); err != nil {
+ return err
+ }
+
+ if gitConf, err = repo.Config(); err != nil {
+ return err
+ }
+
+ gitConf.Raw.SetOption("core", gitFmtConfig.NoSubsection, "hooksPath", s.config.Hooks.Execs)
+ gitConf.Raw.SetOption("receive", gitFmtConfig.NoSubsection, "advertisePushOptions", "true")
+
+ if err = repo.SetConfig(gitConf); err != nil {
+ return err
+ }
+
+ return nil
+}