MCPcopy Create free account
hub / github.com/go-git/go-git / InitWithOptions

Function InitWithOptions

repository.go:94–128  ·  view source on GitHub ↗
(s storage.Storer, worktree billy.Filesystem, options InitOptions)

Source from the content-addressed store, hash-verified

92}
93
94func InitWithOptions(s storage.Storer, worktree billy.Filesystem, options InitOptions) (*Repository, error) {
95 if err := initStorer(s); err != nil {
96 return nil, err
97 }
98
99 if options.DefaultBranch == "" {
100 options.DefaultBranch = plumbing.Master
101 }
102
103 if err := options.DefaultBranch.Validate(); err != nil {
104 return nil, err
105 }
106
107 r := newRepository(s, worktree)
108 _, err := r.Reference(plumbing.HEAD, false)
109 switch err {
110 case plumbing.ErrReferenceNotFound:
111 case nil:
112 return nil, ErrRepositoryAlreadyExists
113 default:
114 return nil, err
115 }
116
117 h := plumbing.NewSymbolicReference(plumbing.HEAD, options.DefaultBranch)
118 if err := s.SetReference(h); err != nil {
119 return nil, err
120 }
121
122 if worktree == nil {
123 _ = r.setIsBare(true)
124 return r, nil
125 }
126
127 return r, setWorktreeAndStoragePaths(r, worktree)
128}
129
130func initStorer(s storer.Storer) error {
131 i, ok := s.(storer.Initializer)

Callers 4

TestInitWithOptionsMethod · 0.85
InitFunction · 0.85
PlainInitWithOptionsFunction · 0.85

Calls 8

NewSymbolicReferenceFunction · 0.92
initStorerFunction · 0.85
newRepositoryFunction · 0.85
setIsBareMethod · 0.80
ReferenceMethod · 0.65
SetReferenceMethod · 0.65
ValidateMethod · 0.45

Tested by 2

TestInitWithOptionsMethod · 0.68