(s storage.Storer, worktree billy.Filesystem, options InitOptions)
| 93 | } |
| 94 | |
| 95 | func 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 | |
| 131 | func initStorer(s storer.Storer) error { |
| 132 | i, ok := s.(storer.Initializer) |
searching dependent graphs…