@@ -71,14 +71,30 @@ type Repository struct {
71
71
wt billy.Filesystem
72
72
}
73
73
74
+ type InitOptions struct {
75
+ // The default branch (e.g. "refs/heads/master")
76
+ DefaultBranch plumbing.ReferenceName
77
+ }
78
+
74
79
// Init creates an empty git repository, based on the given Storer and worktree.
75
80
// The worktree Filesystem is optional, if nil a bare repository is created. If
76
81
// the given storer is not empty ErrRepositoryAlreadyExists is returned
77
82
func Init (s storage.Storer , worktree billy.Filesystem ) (* Repository , error ) {
83
+ options := InitOptions {
84
+ DefaultBranch : plumbing .Master ,
85
+ }
86
+ return InitWithOptions (s , worktree , options )
87
+ }
88
+
89
+ func InitWithOptions (s storage.Storer , worktree billy.Filesystem , options InitOptions ) (* Repository , error ) {
78
90
if err := initStorer (s ); err != nil {
79
91
return nil , err
80
92
}
81
93
94
+ if options .DefaultBranch == "" {
95
+ options .DefaultBranch = plumbing .Master
96
+ }
97
+
82
98
r := newRepository (s , worktree )
83
99
_ , err := r .Reference (plumbing .HEAD , false )
84
100
switch err {
@@ -89,7 +105,7 @@ func Init(s storage.Storer, worktree billy.Filesystem) (*Repository, error) {
89
105
return nil , err
90
106
}
91
107
92
- h := plumbing .NewSymbolicReference (plumbing .HEAD , plumbing . Master )
108
+ h := plumbing .NewSymbolicReference (plumbing .HEAD , options . DefaultBranch )
93
109
if err := s .SetReference (h ); err != nil {
94
110
return nil , err
95
111
}
0 commit comments