MCPcopy
hub / github.com/go-git/go-git / InitWithOptions

Function InitWithOptions

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…