forked from tangled.org/core
Monorepo for Tangled — https://tangled.org
1package git 2 3import ( 4 "errors" 5 "fmt" 6 "os" 7 "path/filepath" 8 9 gogit "github.com/go-git/go-git/v5" 10 "github.com/go-git/go-git/v5/config" 11) 12 13func InitBare(path string) error { 14 parent := filepath.Dir(path) 15 16 if err := os.MkdirAll(parent, 0755); errors.Is(err, os.ErrExist) { 17 return fmt.Errorf("error creating user directory: %w", err) 18 } 19 20 repository, err := gogit.PlainInit(path, true) 21 if err != nil { 22 return err 23 } 24 25 err = repository.CreateBranch(&config.Branch{ 26 Name: "main", 27 }) 28 if err != nil { 29 return fmt.Errorf("creating branch: %w", err) 30 } 31 32 return nil 33}