new recipe default branch main instead of master
This commit is contained in:
parent
d9e60afd71
commit
9510c04aeb
@ -5,14 +5,17 @@ import (
|
||||
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
)
|
||||
|
||||
// Init inits a new repo and commits all the stuff if you want
|
||||
func Init(repoPath string, commit bool, gitName, gitEmail string) error {
|
||||
if _, err := git.PlainInit(repoPath, false); err != nil {
|
||||
repo, err := git.PlainInit(repoPath, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git init: %s", err)
|
||||
}
|
||||
MasterToMain(repo)
|
||||
log.Debugf("initialised new git repo in %s", repoPath)
|
||||
|
||||
if commit {
|
||||
@ -42,3 +45,21 @@ func Init(repoPath string, commit bool, gitName, gitEmail string) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func MasterToMain(repo *git.Repository) {
|
||||
// Create and set the 'main' branch as default
|
||||
ref := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.ReferenceName("refs/heads/main"))
|
||||
if err := repo.Storer.SetReference(ref); err != nil {
|
||||
log.Fatalf("Failed to set 'main' as default branch: %v", err)
|
||||
}
|
||||
// Update the repository configuration
|
||||
cfg, err := repo.Config()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to get repository config: %v", err)
|
||||
}
|
||||
cfg.Init.DefaultBranch = "main"
|
||||
if err := repo.SetConfig(cfg); err != nil {
|
||||
log.Fatalf("Failed to update repository config: %v", err)
|
||||
}
|
||||
fmt.Println("Set 'main' as the default branch.")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user