aboutsummaryrefslogtreecommitdiff
path: root/git_init.go
blob: 2e1063347455559755e0a10f0732bd17845caee5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileContributor: Runxi Yu <https://runxiyu.org>

package main

import (
	"github.com/go-git/go-git/v5"
	git_format_config "github.com/go-git/go-git/v5/plumbing/format/config"
)

// git_bare_init_with_default_hooks initializes a bare git repository with the
// forge-deployed hooks directory as the hooksPath.
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
}