diff options
author | techknowlogick <techknowlogick@gitea.io> | 2023-05-21 02:24:18 -0400 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2023-05-21 02:24:39 -0400 |
commit | 1aa8e8940336aa80eccdd8dd9b46b0e6547e7127 (patch) | |
tree | c08670331d0845a58d33166079d7e0d665ae610d /repository.go | |
parent | 1dbd729a387edb61c89f088cd68040085e6c81bb (diff) | |
download | go-git-1aa8e8940336aa80eccdd8dd9b46b0e6547e7127.tar.gz |
git: Allow Initial Branch to be configurable
Diffstat (limited to 'repository.go')
-rw-r--r-- | repository.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/repository.go b/repository.go index 287b597..ffd4f01 100644 --- a/repository.go +++ b/repository.go @@ -71,14 +71,30 @@ type Repository struct { wt billy.Filesystem } +type InitOptions struct { + // The default branch (e.g. "refs/heads/master") + DefaultBranch plumbing.ReferenceName +} + // Init creates an empty git repository, based on the given Storer and worktree. // The worktree Filesystem is optional, if nil a bare repository is created. If // the given storer is not empty ErrRepositoryAlreadyExists is returned func Init(s storage.Storer, worktree billy.Filesystem) (*Repository, error) { + options := InitOptions{ + DefaultBranch: plumbing.Master, + } + return InitWithOptions(s, worktree, options) +} + +func InitWithOptions(s storage.Storer, worktree billy.Filesystem, options InitOptions) (*Repository, error) { if err := initStorer(s); err != nil { return nil, err } + if options.DefaultBranch == "" { + options.DefaultBranch = plumbing.Master + } + r := newRepository(s, worktree) _, err := r.Reference(plumbing.HEAD, false) switch err { @@ -89,7 +105,7 @@ func Init(s storage.Storer, worktree billy.Filesystem) (*Repository, error) { return nil, err } - h := plumbing.NewSymbolicReference(plumbing.HEAD, plumbing.Master) + h := plumbing.NewSymbolicReference(plumbing.HEAD, options.DefaultBranch) if err := s.SetReference(h); err != nil { return nil, err } |